views:

40

answers:

1

Sorry I can’t log in claim ID is having server issues (im normally Arthur Gibbs)

Data from my database currently outputs this when there are strange charecters...
This is just a example

What I get: De√ilscrat™
What I want: De√ilscrat™

It seems that some characters are being translated into character code by the other guys system..

So what I want to know is:

Is there a function that will expand charecter codes within a string?
Turning FUNCTION(De√ilscrat™) >>> De√ilscrat™.

+6  A: 

Hi,

This √ stuff looks like an HTML entity ; so, let's try de-entitying it...

This can be done using the html_entity_decode function, that's provided by PHP.


For instance, with the string you provided, here's a sample of code :

// So the browser interprets the correct charsert
header('Content-type: text/html; charset=UTF-8');

$input = 'De√ilscrat™';
$output = html_entity_decode($input, ENT_NOQUOTES, 'UTF-8');

var_dump($input, $output);

And the output I'm getting is this one :

string 'De√ilscrat™' (length=19)
string 'De√ilscrat™' (length=15)

(First one is the original version, and second one is the "decoded" version)

So, it seems to do the trick ;-)

Pascal MARTIN
Didn’t know that `html_entity_decode` decodes both numeric and entity character references. The name rather implies that only the latter is supported.
Gumbo
@Gumbo : I wasn't sure about it either -- but it seems to decode them fine, from the test I did (or maybe I got lucky ^^ )
Pascal MARTIN