-1

After upgrading to PHP 5.5, html_entities is returning blank for some strings. Specifically, it seems to be strings that contain French characters. I have tried setting it to UTF-8 but still blank:

htmlentities($str,ENT_COMPAT, 'UTF-8');

Anybody know what's going on here?

My code was working without issue on PHP 5.3.3.

Thanks for any help.

EDIT: Example string from comment

"<h1>Obtenez de meilleurs résultats en moins de temps. Garanti.</h1>" 
ezzarghili
  • 198
  • 14
Andrew
  • 2,691
  • 6
  • 31
  • 47
  • Can you provide the value of `$str` so we can try and replicate? – Jonnix Dec 21 '15 at 17:08
  • might be something else. If you're using deprecated functions, that could be it and `$str` is failing. Use error reporting http://php.net/manual/en/function.error-reporting.php - are you using this with a DB and `mysql_` by any chance with this? Your question is unclear. – Funk Forty Niner Dec 21 '15 at 17:10
  • Here's a string: "

    Obtenez de meilleurs résultats en moins de temps. Garanti.

    "
    – Andrew Dec 21 '15 at 17:17
  • if you have any further info, please post it in your question and not in comments. I asked you something in my comment up there. There could be relevance here and posting exact code used. – Funk Forty Niner Dec 21 '15 at 17:18
  • On the face of it, it seems to work fine. https://3v4l.org/0BYsM – Jonnix Dec 21 '15 at 17:18
  • consult http://stackoverflow.com/questions/279170/utf-8-all-the-way-through-mysql-php-and-html and read all of that. – Funk Forty Niner Dec 21 '15 at 17:20
  • It seems to work fine for me too. I tested on [PHP Tester](http://phptester.net/) using PHP v5.5 – Tom Wright Dec 21 '15 at 17:21

1 Answers1

1

Quote from http://php.net/manual/en/function.htmlentities.php

If the input string contains an invalid code unit sequence within the given encoding an empty string will be returned, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set.

so something like

<?php
$str = "<h1>\xe2 title</h1>";
echo htmlentities($str,ENT_COMPAT, 'UTF-8');

see https://3v4l.org/9OuRE

will return an empty string

ezzarghili
  • 198
  • 14