Question

I have a strange problem with PHP. Basically I was trying to do this:

$string = '&currency_code';

when I try to echo $string the output is:

¤cy_code

Has anyone encountered this? How can we get around this?

Was it helpful?

Solution

&curren is an HTML entity; browsers will render it as the ¤ symbol.

Always run htmlspecialchars on any non-HTML text you want to output to avoid unexpected behavior like this.

$string = "&currency_code";
$escaped_string = htmlspecialchars($string);
echo $escaped_string; // outputs the HTML "&currency_code", which
                      // appears to the user as "&currency_code".
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top