1

It may be a stupid question but I really can't figure it out ... I need to convert a string to html entities, let's take for example:

"cTm ❂ oNe"

If I use http://www.freeformatter.com/html-escape.html#ad-output to convert it I get: "cTm ❂ oNe" which is what I need but if I use php: http://sandbox.onlinephpfunctions.com/

$x = 'cTm ❂ oNe';
echo htmlentities($x);

Tried in CLI as well:

$ cat test2; echo ""; echo ""; php test2
<?php

$x = 'cTm ❂ oNe';
echo htmlentities($x);
?>


cTm ❂ oNe

without a success, what I'm doing wrong here ? Thank you!

$ php -v
PHP 5.4.45-0+deb7u2 (cli) (built: Oct 17 2015 08:26:31)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
    with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v5.0.15, Copyright (c) 2002-2015, by ionCube Ltd.
Musa
  • 96,336
  • 17
  • 118
  • 137
user3405598
  • 85
  • 1
  • 7
  • website is converting htmlentities, on http://www.freeformatter.com/html-escape.html#ad-output i get the escaped version – user3405598 Dec 18 '15 at 14:57
  • Just tested `❂` and it looks like there may be a bug because it's not encoding it for me either. – Enijar Dec 18 '15 at 15:01

1 Answers1

0

According to the documentation on the htmlentities function, PHP versions 5.6 and greater use UTF-8 encoding, but versions prior to that use ISO-8859-1. You may need to call it with the optional argument for encoding specified.

$x = 'cTm ❂ oNe';
echo htmlentities($x, ENT_QUOTES, "UTF-8");
HenryTK
  • 1,287
  • 8
  • 11