0
    $tt="‘Dragon’";
    echo $tt." ".strlen($tt);
    $tt1=html_entity_decode($tt);
    echo $tt1." ".strlen($tt1);

I am trying to decode the above string into 'Dragon' But I am unable to do it as the Output string $tt1 length is not 8 but 12. However, On viewing source code in Chrome, String is converted to 'Dragon'.

Here is the output of the code. If I try to access $tt1[0], then I am not getting ' but � .

‘Dragon’ 20
‘Dragon’ 12
  • 1
    `strlen` doesn't support multibyte encodings. Use `mb_strlen`. – gre_gor Nov 13 '21 at 12:52
  • @gre_gor If I try to access $tt1[0], then I am not getting ' but � – saurabh yadav Nov 13 '21 at 13:12
  • 1
    Same problem. That way you can only access individual bytes, not characters. Either use `mb_substr` or `mb_str_split`. If you are going to manipulate utf-8 strings you should use [`mb_*` functions](https://www.php.net/manual/en/ref.mbstring.php). – gre_gor Nov 13 '21 at 14:29
  • @gre_gor So single byte ' becomes multibyte when it is decoded? – saurabh yadav Nov 13 '21 at 14:57
  • 1
    [What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text](http://kunststube.net/encoding/) – deceze Nov 13 '21 at 15:46

0 Answers0