MrPHP
MrPHP

Reputation: 182

Fix characters in PHP

Anyone know what this is and how to fix it? “The OMG�

<p>After 32 years in its former location, this popular restaurant 
   and bar moved to the bottom of the Avalon Bay Luxury residential building 
   that's just a walk from Angel Stadium. Modern and welcoming, the expansive 
   space is where fans, locals and families gather for upscale twists on classic
   American dishes. Burgers here have a decidedly fun flair like “The OMG� 
   that is a burger surely meant for sharing (with many)--it's so huge that it's 
   served on a 14-inch bun. The restaurant also specializes in seafood with such 
   items as Chilean sea bass, mahi mahi and swordfish. The lounge also serves 
   signature drinks like  the Rally Monkey Martini in tribute to the mascot 
   of the Angels.</p>

This seems to a problem because of a function I have to run on the JSON data before decoding it or JSON decoding will fail:

function safeJSON_chars($data) {
$aux = str_split($data); 
foreach($aux as $a) { 
    $a1 = urlencode($a); 
    $aa = explode("%", $a1); 
    foreach($aa as $v) { 
        if($v!="") { 
            if(hexdec($v)>127) { 
            $data = str_replace($a,"&#".hexdec($v).";",$data); 
            } 
        } 
    } 
} 
return $data;}

Upvotes: 3

Views: 4357

Answers (5)

jazkat
jazkat

Reputation: 5788

I found this helpful: str_replace() equivalent for Multi-byte string like UTF-8

Then use it like this:

$replace = array("&Scaron;");
$replace = array("&scaron;");
$search = array("Š"); 
$search = array("š");  

$queryText= mb_replace($search, $replace, $queryText);

Upvotes: 1

Michiel Pater
Michiel Pater

Reputation: 23033

Have a look at this page

Unicode-friendly PHP and MySQL

On this page you will find an easy and clear explaination of UTF-8 encoding and how to apply this in your websites along with some practical examples.

You will also need to make sure that your files are saved using UTF-8 encoding (without BOM).

Upvotes: 6

Michael Berkowski
Michael Berkowski

Reputation: 270617

In PHP, you can set the page charset:

header("Content-type: text/html; charset=utf-8");

Upvotes: 2

VoronoiPotato
VoronoiPotato

Reputation: 3173

Those would be microsoft quotes in Unicode utf-8.

Upvotes: 1

jpea
jpea

Reputation: 3079

Is your character-set set to Latin1 perhaps? Try using UTF-8 and see if that fixes it.

Upvotes: 1

Related Questions