views:

352

answers:

2

Hello,

I'm trying to decode encoded long dash from numeric entity to string, but it seems that I can't find a function which can do this properly.

The best that I found is mb_decode_numericentity(), however, for some reason it fails to decode long dash and some other special characters.

$str = '–';

$str = mb_decode_numericentity($str, array(0xFF, 0x2FFFF, 0, 0xFFFF), 'ISO-8859-1');

This will return "?".

Anyone knows how to solve this problem?

A: 

8211 is a decimal Unicode character code point. In hexadecimal, that's 2013.

$str = '\u2013';
Delan Azabani
But he's decoding HTML entities, so the input will be in the format he used, presumably.
Anthony
A: 

mb_decode_numericentity does not handle hexadecimal, only decimal. Do you get the expected result with:

$str = '–';

$str = mb_decode_numericentity ( $str , Array(255, 3145727, 0, 65535) , 'ISO-8859-1');

You can use hexdec to convert your hexadecimal to decimal.

Also, out of curiosity, does the following work:

$str = '–';

 $str = html_entity_decode($str);
Anthony
Thanks for a quick reply, but this returns '?' as well.
Yuriy
>$str = html_entity_decode($str);That was the first thing I tried.No.
Yuriy