Using htmlentities() in preg_replace()
Posted: Sun Oct 08, 2006 1:57 pm
I'm trying to run the htmlentities() function inside a preg_replace() like so:
Basically this line is supposed to replace anything between <code> and </code> with the htmlentities() output.
Example:
- Before function
- After function
I'm getting the error of an unexpected character, the two '\' I use inside htmlentities(). I don't know how else to use the backreference. Any ideas?
Code: Select all
preg_replace("<code>(.*)</code>", "<code>".htmlentities(\\1)."</code>", $tutorial);Example:
- Before function
Code: Select all
<code><?php echo "hello world"; ?></code>Code: Select all
<code><php echo "hello world"; ?></code>