开发者

Unknown characters like †in the string

开发者 https://www.devze.com 2023-03-12 18:34 出处:网络
I\'m getting unknown characters when I echo data on web page. testing.doc contains buy the stock \"cheap\" before the rest of the market

I'm getting unknown characters when I echo data on web page. testing.doc contains

buy the stock "cheap" before the rest of the market

$data = file_get_contents('testing.doc');

$soap->SetLocalTemplate(
   array(
        'template' => base64_encode($data),
        'format'   => 'doc'
    )
);

$soap->CreateDocum开发者_如何学运维ent();
        $result = $soap->RetrieveDocument(
            array(
                'format' => 'txt'
            )
        );

$data = $result->RetrieveDocumentResult;
file_put_contents(file.txt', base64_decode($data));

If i read the text file file.txt I get the exact text as stored in testing.doc but if I do like this :

echo base64_decode($data);

I get

buy the stock “cheap†before the rest of the market

Now there are some unknown characters. Please tell me how resolve this issue?


Looks like a character encoding issue.

If the encoding set your web page is using differs from the source where you're grabbing content from, then you will get funny characters like the above.


Your page is probably treated as ISO-8859-1 encoded, but the XML data is in UTF-8.

Either change your output encoding to UTF-8, or use iconv() to convert it to ISO-8859-1.


As others have mentioned, XML data has UTF-8 encoding.

For echoing things to a browser, you should set the header, especially when you know the encoding of what you're trying to echo:

header('content-type:text/html;charset=utf8');

This goes right before the call to echo. For example:

/* get content, set it to $content */

header('content-type:text/html;charset=utf8');
echo $content;
0

精彩评论

暂无评论...
验证码 换一张
取 消