views:

28

answers:

2

Some Wordpress plugins (one is MapPress which uses Google Maps) use ampersands in their links but do not convert them into the correct HTML character entity:

&

This invalidates the markup and is very frustrating! Is there any way to convert the & to &?

I've searched for a long time and found no solution, but have read a lot of interesting articles on the topic!

+3  A: 

I think you're looking for htmlentities: http://php.net/manual/en/function.htmlentities.php

<?php
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>
David Titarenco
+2  A: 

I'd write an email to him and ask him to use htmlentities in his plugin. Even better, make the changes yourself, then email him a patch.

Douglas
Both David and Douglas are right on this: it's a fairly straightforward fix, but it really wants to find its way back into the code base of the project it came from. If you don't do that you have effectively created a mini-fork of the plugin and you'll have to re-patch it every time there's an update.
Peter Rowell
I have already contacted the author about this.. looks like I'll have to try and patch it myself (and send him the updated files!) ;)
Jonny Wood