March 6th, 2009, 07:05 PM
PHP GREP - single to double quote in tags
I have a string like:
I want to change the string so all the ' become " inside the tag, but so it does not affect the ' in Bob's:
<p class='essay_caption'>This is Bob's test</p>
I'm using PHP 5 and wonder if this can be done with ereg_replace.
<p class="essay_caption">This is Bob's test</p>
Thanks for any help
March 6th, 2009, 08:52 PM
This will replace the ' in Bob's,
Now that I got you started, i'll leave you to do the reverse.
March 7th, 2009, 01:54 AM
So all you really want to do is replace all the apostrophes in HTML tags with quotes?
$text = "<p class='essay_caption'>This is Bob's test</p>";
echo preg_replace('/<([^<>]+)>/e', '"<" . str_replace("\\\\\'", \'"\', "$1") . ">"', $text);
March 7th, 2009, 10:00 AM
requinix - thank you!
That is exactly what I needed.