NucleaDisasta Posted December 9, 2008 Share Posted December 9, 2008 k so i'm developing a webapp where people will paste a Copy paste of a webpage (not the source) from firefox and then it will spit out some results. The problem is though that for the regex i have in place i need to rip out the "newline" and "tab" characters before the regex will "see" the patterns i'm looking for. I've tested the patterns i'm looking for on an input that has had the "newline" and "tab" characters removed before being input and it works perfectly. The piece of code i am using to strip out the "newline" and "tab" characters is thus: // Strip line breaks, commas and tabs $line_breaks = array('\r\n', '\n', '\r', '\t', ','); $nationUse = str_replace($line_breaks, "", $nationIn); Now this piece of code is stripping out the commas from the input so I know that its doing something. It is not stsripping out any of the rest of the characters though and i'm at a loss as to why. Any ideas? Also the server this issue is happening on has a PHP version of 5.2.6 Link to comment https://forums.phpfreaks.com/topic/136165-solved-str_replace-not-working-as-it-should/ Share on other sites More sharing options...
xtopolis Posted December 9, 2008 Share Posted December 9, 2008 I think it has something to do with how the \r\n's are being interpreted. I think you either need to place them in double quotes: "\r\n" ( array("\r\n","\r") ), and/escape the backslashes.. Link to comment https://forums.phpfreaks.com/topic/136165-solved-str_replace-not-working-as-it-should/#findComment-710213 Share on other sites More sharing options...
NucleaDisasta Posted December 9, 2008 Author Share Posted December 9, 2008 I'll try the Double Quotes now Link to comment https://forums.phpfreaks.com/topic/136165-solved-str_replace-not-working-as-it-should/#findComment-710216 Share on other sites More sharing options...
NucleaDisasta Posted December 9, 2008 Author Share Posted December 9, 2008 Twas the Single Quotes causing the problem. Thanks for the help Link to comment https://forums.phpfreaks.com/topic/136165-solved-str_replace-not-working-as-it-should/#findComment-710219 Share on other sites More sharing options...
redarrow Posted December 9, 2008 Share Posted December 9, 2008 works fine m8...... <?php $nationIn="<html><head><title></title></head><body> hi there\r\n i am redaarow\n how are you\r yee\t haa,</body></html>"; $line_breaks = array("\r\n", "\n", "\r", "\t", ","); $nationUse = str_replace($line_breaks, " ", $nationIn); echo $nationUse; ?> Link to comment https://forums.phpfreaks.com/topic/136165-solved-str_replace-not-working-as-it-should/#findComment-710228 Share on other sites More sharing options...
NucleaDisasta Posted December 9, 2008 Author Share Posted December 9, 2008 Aye it works fine with Double Quotes. I was using Single Quotes. Link to comment https://forums.phpfreaks.com/topic/136165-solved-str_replace-not-working-as-it-should/#findComment-710235 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.