Jump to content

Confusing issue using unicode chars with php


XENOTnet

Recommended Posts


<?php
//RETURNS "–—–––———––—–—–––—–—–—––—––––———––––———––"
$string1 = file_get_contents("https://api.abc.xyz/myScript/index.php/");

//Which should be the same as the first one.
$string2 = "–—–––———––—–—–––—–—–—––—––––———––––———––";

file_put_contents("debug.txt", $string1."\n".$string2);
?>

When I open the file I get the following output:


–—–––———––—–—–––—–—–—––—––––———––––———––
—–—————–—–——–––—–——––—––————–——–—–—————–—–——–––—–——––—––————–——–

On my website however I get this output:


����������������������������������������
–—–––———––—–—–––—–—–—––—––––———––––———––

Why do string1 and string2 output different chars?

"What's the problem" you may ask. String1 (which comes from my api) can't be displayed on my page and String2 can.

BUT

String1 (which comes from my api) can be wrote to file correctly but String2 can't.

Image here: http://image.prntscr.com/image/87228bf0bc8c4259a09a51245c52f9f7.png

>>> How can I get String1 to display properly? <<<

Link to comment
Share on other sites

The string from your API and the string in your source code use two different encodings (I'm guessing ISO 8859-1 and UTF-8). Your editor and your page are also using different encodings, so you get an interesting collection of encoding problems.

 

To fix this, use UTF-8 everywhere, particularly in your API.

Edited by Jacques1
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.