For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > August 2007 > preg_replace NULL









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author preg_replace NULL
PHPLearningNeeds

2007-08-11, 1:42 am

I am trying to make a line where I can do a preg_replace on a null character using the or wild card. For example, I wish to replace

$text="I am OK. <br>
How are you?"

OR

$text="I am OK.<br>
How are you?"

with

$newtext="I am OK. How are you?"

I have tried $newtext=preg_replace("/(.*?)([\0|" . chr(32) . "]<br>\r(.*?)/i","\\1 \\3",$text), but I got a warning that I did not have an end delimiter, which I obiously do. I also tried $newtext=preg_replace("/(.*?)([|" . chr(32) . "]<br>\r(.*?)/i","\\1 \\3",$text), but it didn't replace properly. How do I fix this problem without using two statements?
PHPLearningNeeds

2007-08-11, 1:44 am

Oh, and I've also tried $newtext=preg_replace("/(.*?)([" . chr(0) . "|" . chr(32) . "]<br>\r(.*?)/i","\\1 \\3",$text), but that didn't work either.
PHPLearningNeeds

2007-08-11, 1:45 am

Eek, oops. I forgot to put in the \'s before the < and > in the HTML line breaks, but I DID include them in my original code.
PHPLearningNeeds

2007-08-11, 1:50 am

I wish this site had the edit ability for comments.

For clarification, this is my EXACT code that isn't working.

<?
$test="I am OK.<br>
How are you?";

$newtext=preg_replace("/(.*?)([" . chr(0) . "|" . chr(32) . "])\<br\>(.*?)/i","\\1 \\3",$test);

echo $newtext;
?>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com