Jump to content

PHP character encoding problem


inzania

Recommended Posts

I seem to be having some sort of character encoding problem.  The basic situation is this: I'm using CURL to retrieve data from an external webpage and then parse the results.  The result of this is a Chinese string.  So far so good.

 

When I echo the results, though, they come out as �s.  Confused, I tried comparing the output to a hard-coded string which is known to exactly match the results.  Please see below, assuming $definition has already been set by the aforementioned CURL function.

 

function OrdOut($str)
{
$out = array();
for($i=0; $i<strlen($str); $i++)
{
	$out[] = dechex(ord($str[$i]));
}
echo($str."=>".implode(":",$out)."<br>");
}
$correct = "歌曲";
OrdOut($correct);
OrdOut($definition);

 

This outputs the following:

歌曲=>e6:ad:8c:e6:9b:b2
����=>b8:e8:c7:fa

 

$definition SHOULD exactly match $correct, but it doesn't seem to.  I'm afraid this might have something to do with CURL and parsing Chinese text, and the headers on the page being retrieved not being correct.  It strikes me as curious the difference in string lengths between the two of them, which seems to indicate some sort of different encoding, but I could be completely off.

 

I appreciate any help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.