Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cut out tabs and breaks

Status
Not open for further replies.

lukelukeluke

Technical User
Dec 23, 2003
117
CH
hi guys,
i was wondering if there are functions to kill tabs and breaks...
my variable looks like this:

$var1 = " some
content of m
y variable "

it should be like
$var1 = "some content of my variable"

how can i shorten it?

Webmaster of knowledgebase for IT knowledge.
 
Maybe something like this:

Code:
$var1 = "        some
content of m
y variable            ";

$var1 = trim($var1);
$var1 = str_replace("\n", "", $var1);
$var1 = str_replace("\r", "", $var1);
$var1 = str_replace("\r\n", "", $var1);

echo $var1;

*cLFlaVA
----------------------------
When will I be able to see what other members can see about myself? It's been like, a freakin' month already!
 
What about a quick regex?
Code:
$pattern = "/(\n|\r|\t)/";
$newString = preg_replace($pattern,'', $string);
 
Fine with me. One cannot give regex solutions when one cannot figure out regex's for the life of himself.

:)

*cLFlaVA
----------------------------
When will I be able to see what other members can see about myself? It's been like, a freakin' month already!
 
thanks alot for the answers!
i tried to string_replace some like these:
$replace1 = "
";
$replace2 = " ";

but now i see that you have to replace \n and \t..
thanks!

Webmaster of knowledgebase for IT knowledge.
 
if you want to transform the \n to <br>, use nl2br() (good for cms handling)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top