PHP: Get text content scrambled by UTF-8

hankknight
hankknight used Ask the Experts™
on
Somehow the data in a MySQL database ended up in a format that looks like this.

Using PHP, is there any way I can get the actual text from this?

I tried using mb_convert_encoding() and I also tried using utf8_decode() but I cannot figure out how to get actual text content from this:

"0S"0h"0o"0r"0t"0l"0i"0s"0t"0e"0d"0 "0f"0o"0r"0 "0t"0h"0e"0 "02"00"01"01"0 "0F"0r"0a"0n"0k"0 "0O "0C"0o"0n"0n"0o"0r"0 "0S"0h"0o"0r"0t"0 "0S"0t"0o"0r"0y"0 "0A"0w"0a"0r"0d"0,"0 "0t"0h"0e"0 "0w"0o"0r"0l"0d"0'"0s"0 "0r"0i"0c"0h"0e"0s"0t"0 "0s"0h"0o"0r"0t"0 "0s"0t"0o"0r"0y"0 "0p"0r"0i"0z"0e"0 "0 "0 "0 "0""0T"0r"0a"0f"0f"0o"0r"0d"0'"0s"0 "0a"0l"0c"0h"0e"0m"0i"0c"0a"0l"0 "0m"0i"0x"0i"0n"0g"0 "0o"0f"0 "0r"0e"0s"0e"0a"0r"0c"0h"0,"0 "0f"0a"0b"0l"0e"0,"0 "0p"0a"0t"0h"0o"0s"0,"0 "0a"0n"0d"0 "0p"0l"0o"0t"0 "0y"0i"0e"0l"0d"0s"0 "0i"0m"0p"0r"0e"0s"0s"0i"0v"0e"0 "0r"0e"0s"0u"0l"0t"0s"0."0""0-"0R"0a"0i"0n"0 "0T"0a"0x"0i"0 "0 "0 "0 "0""0I"0 "0l"0o"0v"0e"0 "0M"0a"0t"0h"0e"0w"0 "0J"0."0 "0T"0r"0a"0f"0f"0o"0r"0d"0'"0s"0 "0i"0m"0a"0g"0i"0n"0a"0t"0i"0o"0n"0!"0 "0I"0n"0 "0h"0i"0s"0 "0w"0o"0r"0l"0d"0,"0 "0s"0c"0i"0e"0n"0t"0i"0s"0t"0s"0 "0c"0l"0o"0n"0e"0 "0J"0e"0s"0u"0s"0 "0C"0h"0r"0i"0s"0t"0,"0 "0f"0i"0s"0h"0e"0r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"0 "0e"0l"0e"0v"0a"0t"0o"0r"0 "0t"0a"0k"0e"0s"0 "0y"0o"0u"0 "0t"0o"0 "0a"0n"0o"0t"0h"0e"0r"0 "0f"0l"0o"0o"0r"0 "0a"0l"0t"0o"0g"0e"0t"0h"0e"0r"0,"0 "0a"0n"0d"0 "0i"0t"0 "0t"0u"0r"0n"0s"0 "0o"0u"0t"0 "0t"0o"0 "0b"0e"0 "0a"0 "0t"0h"0o"0r"0o"0u"0g"0h"0l"0y"0 "0e"0n"0j"0o"0y"0a"0b"0l"0e"0 "0r"0i"0d"0e &"0 "0a"0 "0m"0u"0s"0t"0 "0f"0o"0r"0 "0r"0e"0a"0d"0e"0r"0s"0 "0l"0o"0o"0k"0i"0n"0g"0 "0f"0o"0r"0 "0s"0o"0m"0e"0t"0h"0i"0n"0g"0 "0f"0r"0e"0s"0h"0 "0a"0m"0i"0d"0 "0a"0 "0s"0e"0a"0 "0o"0f"0 "0s"0t"0a"0l"0e"0 "0b"0o"0o"0k"0s"0.  "0Q"0u"0i"0l"0l"0 "0a"0n"0d"0 "0Q"0u"0i"0r"0e"0 "0

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016
Commented:
The Joel Spolsky article is important reading.
<?php // RAY_temp_hankknight.php
error_reporting(E_ALL);
echo "<pre>";

// SEE http://www.joelonsoftware.com/articles/Unicode.html
// MUNGED DATA FROM THE POST AT EE
$str = <<<STR
"0S"0h"0o"0r"0t"0l"0i"0s"0t"0e"0d"0 "0f"0o"0r"0 "0t"0h"0e"0 "02"00"01"01"0 "0F"0r"0a"0n"0k"0 "0O "0C"0o"0n"0n"0o"0r"0 "0S"0h"0o"0r"0t"0 "0S"0t"0o"0r"0y"0 "0A"0w"0a"0r"0d"0,"0 "0t"0h"0e"0 "0w"0o"0r"0l"0d"0'"0s"0 "0r"0i"0c"0h"0e"0s"0t"0 "0s"0h"0o"0r"0t"0 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 "0f"0o"0r"0 "0s"0o"0m"0e"0t"0h"0i"0n"0g"0 "0f"0r"0e"0s"0h"0 "0a"0m"0i"0d"0 "0a"0 "0s"0e"0a"0 "0o"0f"0 "0s"0t"0a"0l"0e"0 "0b"0o"0o"0k"0s"0.  "0Q"0u"0i"0l"0l"0 "0a"0n"0d"0 "0Q"0u"0i"0r"0e"0 "0
STR;

// GET AN ARRAY OF "WORDS"
$words = explode(' ', $str);

// DECONSTRUCT AND RECONSTRUCT EACH "WORD"
$out = array();
foreach ($words as $word)
{
    $arr = explode('"', $word);
    foreach ($arr as $ltr)
    {
        $ltr = ltrim($ltr, '0');
        $new .= $ltr;
    }
    $out[] = $new;
    $new = NULL;
}
$new = implode(' ', $out);
print_r($new);

Open in new window

HTH, ~Ray

Author

Commented:
Thanks, Ray, that was very helpful!
Most Valuable Expert 2011
Top Expert 2016

Commented:
Thanks for the points -- best of luck with it, ~Ray

Commented:
Hello,

Ai need of function

$str = <<<STR
"0S"0h"0
STR;

change:

$str = <<<STR
.$var.
STR;

erro...
Most Valuable Expert 2011
Top Expert 2016

Commented:
@jjmelo:  Consider posting a question of your own here!  We are glad to help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial