Stefan Brendle
Stefan Brendle

Reputation: 1564

Decode Unicode chars in PHP by the unicode number

I've got characters like

- 

or

 

The number 45 is the unicode number "#". The "32" is a simple space. But this also have to be possible with numbers like "2123" for some very special special chars.

Now I want to simply decode this characters in PHP. My first try was to use:

htmlspecialchars_decode();

But this does not work for "#", only for special chars like "ö" or "Ä".

It would be no problem to create a new function for my case (if there is no build-in php-function), but I couldn't find a equivalent function for mssql-server functions like NCHAR() or UNICODE() - which simply return the unicode number of a character and vice versa.

Thank you :)

Upvotes: 0

Views: 354

Answers (1)

Álvaro González
Álvaro González

Reputation: 146660

The behaviour you've found is exactly what's documented:

This function is the opposite of htmlspecialchars(). It converts special HTML entities back to characters.

The converted entities are: &, " (when ENT_NOQUOTES is not set), ' (when ENT_QUOTES is set), < and >

You want some other related function, so we scroll down the documentation to the See Also section and find html_entity_decode():

Convert all HTML entities to their applicable characters

var_dump( htmlspecialchars_decode('- ') );
var_dump( html_entity_decode('- ') );
string(10) "- "
string(2) "- "

Upvotes: 2

Related Questions