syedasimmeesaq
asked on
\r\n in a textbox
In my database I have new line starts as this \r\n
now I want to show this data online. The problem is that when I echo it out, instead of showing next line, it just outputs \r\n
how can I fix that so it out put another line and has correct formatting
Thanks
now I want to show this data online. The problem is that when I echo it out, instead of showing next line, it just outputs \r\n
how can I fix that so it out put another line and has correct formatting
Thanks
textboxes take literal text...you would have to use: <br />
hielo again!!! we always meet this way...:0P
ASKER
the problem is that in database it looks like this
ABC
DE
FG
I do not see and \r\n
but when I echo it I see there. I tried heilos method but no go
I am trying rays now.
Thanks
ABC
DE
FG
I do not see and \r\n
but when I echo it I see there. I tried heilos method but no go
I am trying rays now.
Thanks
perhaps your data contains just \n not \r\n:
echo str_replace("\n","<br />", $str);
echo str_replace("\n","<br />", $str);
ASKER
when I echo my variable
echo $var;
it gives me
ABC
\r\nDE
\r\nFG
I tried all methids but still no go
echo $var;
it gives me
ABC
\r\nDE
\r\nFG
I tried all methids but still no go
so this has to do more with what symbol the db is actually spitting out...
try this: echo "$var";
Try
echo "<pre>";
echo stripslashes($var);
echo "</pre>";
ASKER
that didn't do anything either
syedasimmeesaq: What "didn't do anything either?" Please post what you did and what output you got, OK? We are just experts, not mind readers! Thanks, ~Ray
Ray, he was probably on an old page when he was tryin your code...so I think he means yours and didn't see NoiS yet...actually they should probably have a refresh button/trigger to prevent that type of confusion...
they meaning: Experts-Exchange...
Yeah, that makes sense. I'll stand by and wait for clarification and sample output.
ASKER
echo "$var"; didn't do anything. Also I made a discovery when I do this
echo str_replace("r","<br />", $var); only then it put it in the next line but the problem is that it still gives a slash before next line and in next line it enters \n
thanks
Also <PRE> didn't work either
echo str_replace("r","<br />", $var); only then it put it in the next line but the problem is that it still gives a slash before next line and in next line it enters \n
thanks
Also <PRE> didn't work either
ASKER
ok got it
str_replace("\\r\\n","<br />", $var);
since its closest to heilos suggestion, I think he desrves the points
Thank you all for your help
str_replace("\\r\\n","<br />", $var);
since its closest to heilos suggestion, I think he desrves the points
Thank you all for your help
try this:
echo str_replace('\r\n',"<br />", $str);
notice the apostrophes around \r\n, NOT double quotes
echo str_replace('\r\n',"<br />", $str);
notice the apostrophes around \r\n, NOT double quotes
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
nice job syedasimmee&
figured it out yourself...good going...
You are missing something;
if your text was saved on database with \r\n and magic_quotes are ON on PHP, it will escape with one more slashe, so, when you echo the $var only one slash will be removed. This is the correct behaviour. But if for some strange reason (possibly an error bettwen POST and retrieve) when you retrieve the data are putting twice, You need to treat it.
the code below MUST print differente results
if your text was saved on database with \r\n and magic_quotes are ON on PHP, it will escape with one more slashe, so, when you echo the $var only one slash will be removed. This is the correct behaviour. But if for some strange reason (possibly an error bettwen POST and retrieve) when you retrieve the data are putting twice, You need to treat it.
the code below MUST print differente results
echo $var . "<br >";
echo stripslashes($var) . "<br >";
echo preg_replace("#(\r|\n|\\r|\\n)#","<br />",$var);
My Post was late...
plus Hielo was the reason we got to the solution in the first place...
Open in new window