问题
In PHP when i read the Data, let say the data (chunks of strings) is containing HTML Special Character DECIMAL HEX Codes like:This is a sample string with œ and š
We can say above HEX codes are the source codes of its correspondence Symbol and these will be rendered as correct Symbols in Browser.
But what i want to do is, for these characters (for example), i want these HEX(es) as the converted original Character Symbols like:This is a sample string with œ and š
So how can i detect the any of decimal HEX Codes inside a string and convert each of them into final Symbol(s), instead of keeping HEX codes?
Note:
For more clearence, is there any function to detect and convert the Hex to Symbol?
Like:œ
=> œ
š
=> š
回答1:
$s = "This is a sample string with œ and š";
echo html_entity_decode($s, ENT_COMPAT, 'UTF-8');
回答2:
Those are HTML entities - you can go back to actual symbol with html_entity_decode().
回答3:
make sure anything you use (database tables, json or xml for data exchange, html files etc etc etc) is in UTF-8 format
来源:https://stackoverflow.com/questions/12334022/php-to-detect-and-convert-special-characters