Question about ereg_replace

It’s been a few years since I came up with this code for my website. I’m pretty sure it puts a <br> where there are hard returns in a body of text.

$testimony	= ereg_replace(10,"<br>",$testimony);
$testimony	= ereg_replace(34,"'",$testimony);

My question is this. What is the best way to reverse this process? I am emailing out text from the database that now has <br> tags in it.


ereg_replace has been deprecated.
You should use preg_replace instead.

To reverse this process, you should be able to use this:
preg_replace(“/<br>/g”, "
", $testimony);

Excellent, thank you.

But what is this code doing?

$testimony    = ereg_replace(34,"'",$testimony);  

Oooops, I spoke too soon. When I went to implement the new snip of code, I got the following error:

Warning: preg_replace() [function.preg-replace]: Unknown modifier 'g' in /home3/recordau/public_html/oil-testimonials/sendEmail.php on line 293

Sorry, that’s my fault. preg_replace doesn’t take g as a modifier for global replacing. Just remove the g at the end of it, and it should work fine.

As for your other question, based on the number I’d say it’s replacing any character of ASCII value 34 with a single quote character - which is odd, since I’m fairly sure that’s what it is anyhow.

There’s no reason to use preg_replace here, str_replace should suffice.

Here is the error I’m getting now:

Warning: preg_replace() [function.preg-replace]: No ending delimiter ‘/’ found in /home3/recordau/public_html/oil-testimonials/sendEmail.php on line 313

Here is the code without the /g

preg_replace(“/<br>”, "
", $testimony);

Any suggestions?


Yes, don’t use Regular Expressions.