夏期劇場
夏期劇場

Reputation: 18327

PHP to detect and convert Special Characters?

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:
œ => œ
š => š

Upvotes: 3

Views: 3510

Answers (3)

fd8s0
fd8s0

Reputation: 1927

$s = "This is a sample string with œ and š";
echo html_entity_decode($s, ENT_COMPAT, 'UTF-8');

Upvotes: 2

moonwave99
moonwave99

Reputation: 22817

Those are HTML entities - you can go back to actual symbol with html_entity_decode().

Upvotes: 1

Evert S
Evert S

Reputation: 19

make sure anything you use (database tables, json or xml for data exchange, html files etc etc etc) is in UTF-8 format

Upvotes: -1

Related Questions