Character Format in php

288 views Asked by At

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™.

1

There are 1 answers

2
Pascal MARTIN On

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 ;-)