XENOTnet Posted September 8, 2016 Share Posted September 8, 2016 <?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? <<< Quote Link to comment https://forums.phpfreaks.com/topic/302110-confusing-issue-using-unicode-chars-with-php/ Share on other sites More sharing options...
Jacques1 Posted September 8, 2016 Share Posted September 8, 2016 (edited) The string from your API and the string in your source code use two different encodings (I'm guessing ISO 8859-1 and UTF-. 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 September 8, 2016 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/302110-confusing-issue-using-unicode-chars-with-php/#findComment-1537199 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.