Here's the scenario. I need to strip out any carriage returns before a field is submitted into my database. The field in question is used to populate “OverLib”(JS app used to generate pop over windows)
If there are any Carriage returns within the string given to “OverLib” the JS has a wobbly. Plus the carriage returns are untidy.
Here are my unsuccessful efforts to strip out the offending carriage returns.
Does anyone have the answer?
1. $New = str_replace('\r', '', $New);
2. $New = str_replace('\n', '', $New);
3. $New = str_replace('^M', '', $New);
4. $New = str_replace('
’, '', $New);
damn darn carriage return
Moderator: General Moderators
-
sleepingdanny
- Forum Newbie
- Posts: 12
- Joined: Thu Mar 20, 2003 4:27 am
- Location: Israel
Might be worth pulling out the old nl2br - I am not sure how clever the function is though. If it really replaces everything with "<br />" then use that as a placeholder which you replace.
What is quite interesting are the usernotes to nl2br in the manual:
What is quite interesting are the usernotes to nl2br in the manual:
If all else fails, try the ereg_replace above (slighlty modified I suppose).Macintosh: \r
Unix : \n
Windows : \r\n
The code below allows the line endings to be easily replaced with a br tag on any of the three major OSs.
-zak@php.net]
Well, there's some major issues with NewLine codes vs OS (win, linux, mac). Here is what I use : $s_data = ereg_replace("(\r\n|\n|\r)", "<br />", $s_data);
So far it worked great for me.
You beatuie
Nice one patrikG!
$New = ereg_replace("(\r\n|\n|\r|^M)", "", $New);
did the job.
Danny,
thanks for the help. As far as i am aware "TRIM" only strips from the end and the beginig of a string.
Thanks again,
Deddog.
$New = ereg_replace("(\r\n|\n|\r|^M)", "", $New);
did the job.
Danny,
thanks for the help. As far as i am aware "TRIM" only strips from the end and the beginig of a string.
Thanks again,
Deddog.