Question

i'm testing the exact same functionality in two different environments, one is a local development environment, and the other is a staging server. they have the exact same code.

when I do a curl request to each endpoint containing the functionality, I get two different results:

Local (php 5.4)

//this was the desired output
<p><span>Awesome water shooting power</span></p>

Staging (php 5.3)

//none of the html chars are changed.
<p><span>Awesome water shooting power</span></p>

the actual string of text is being run through htmlspecialchars in the following way:

htmlspecialchars( $req->get('description') )

Should I be specifically using all of the other arguments in this htmlspecialchars method in order to make it behave the same way in any environment? or is there something at the php.ini level that could be happening?

Was it helpful?

Solution

in the php documentation for htmlspecialchars:

Encoding: Defines encoding used in conversion. If omitted, the default value for this argument is ISO-8859-1 in versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0 onwards.

so, based on that, I tried setting the fields explicitly, so they would not default to different things silently.

htmlspecialchars( $string , ENT_COMPAT, 'UTF-8' );

now the output is the same between the two different environments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top