PHP Special Characters

When I post text of £ 3.99 per M² from an XML file, the browser displays it as  £ 3.99 per M². The XML file is in UTF-8 format. I wonder how to fix it.

+4
source share
2 answers

Make sure you output UTF-8. This conversion sounds like your source is UTF-8, but you tell the browser to expect something else (Latin1?). You should send a header pointing to the UTF-8 browser, and you should have the correct meta header:

<?php header ('Content-type: text/html; charset=utf-8'); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <?php echo "£3.99 per M²"; ?> </body> </html> 

This should work correctly.

+6
source

You must encode html objects:

you may try

 htmlentities($str, ENT_QUOTES, "UTF-8"); 

Look here for full reference.

If you still have problems, sometimes you also need to decode the string using utf8_decode () so you can try:

 $str = utf8_decode($str); $str = htmlentities($str, ENT_QUOTES); 
+3
source

Source: https://habr.com/ru/post/890042/


All Articles