using preg_replace on html entities
Posted: Sun Sep 24, 2006 6:26 pm
I parse a tutorial by running htmlentities to 'sanitize the tags', but there are some tags I need to have unmodified.
This is my code:
What I want it to do is replace <acronym>, <b>, <code>, etc with <acronym>, <b>, <code>, etc.
The problem is that when it finds an occurance of one of these types of tags, it replaces it with /<(acronym|b|code|i|q|u)>/.
Is there a way to set some sort of place holder to the replacement regex knows what tag it's modifying?
ex.
Tutorial has <acronym> in it
htmlentities tranfers it to <acronym>
preg_replace finds <acronym>, remembers that 'acronym' is the text and replaces it with <acronym>
This is my code:
Code: Select all
$tutorial = htmlentities($tutorial);
$tutorial = preg_replace("/<(acronym|b|code|i|q|u)>/", "/<(acronym|b|code|i|q|u)>/", $tutorial);The problem is that when it finds an occurance of one of these types of tags, it replaces it with /<(acronym|b|code|i|q|u)>/.
Is there a way to set some sort of place holder to the replacement regex knows what tag it's modifying?
ex.
Tutorial has <acronym> in it
htmlentities tranfers it to <acronym>
preg_replace finds <acronym>, remembers that 'acronym' is the text and replaces it with <acronym>