PHP - Unicode characters not displaying correctly in console












0















Whenever I use PHP 7.2 to print a string to the console and it contains a unicode character to the console, it doesn't display correctly. For example, a £ displays as ┬ú.



It's not the console, as I can echo £ with no problem.



It's not the PHP version. Upgrading it the latest stable version or downgrading it down as far as version 5.6 does not fix it. I've used online emulators using the same versions and they don't have this problem, although they are outputting to a web page. However, it's irrelevant, because I know that this used to work in 5.6 and now does not.



The problem became apparent when I tried to catch an Exception which contained a £ sign in the string. Nothing would happen. The script would halt and no error would be displayed. It took me over an hour to discover that it had something to do with the £ symbol in the string which stops PHP dead in it's tracks, so the problem HAS to be PHP - I just don't know what.



Does anyone have any ideas as to what could be causing this?










share|improve this question













migrated from superuser.com Jan 19 at 18:07


This question came from our site for computer enthusiasts and power users.



















  • What OS is PHP running on?

    – grawity
    Jan 19 at 17:38






  • 1





    This has been a traditional problem in Windows but I think it's been fixed in 7.x versions. Are you on Windows 10? Can you see the error message if you print it to a file?

    – Álvaro González
    Jan 19 at 18:16













  • Sorry, I forgot to mention. I'm on Windows 7 Ultimate. It used to work fine. Something seems to have changed. I'm going to try it out on my other Win7 rig and see what happens. I suspect it will work fine.

    – thefuzzy0ne
    Jan 19 at 19:26











  • Your console is interpreting text not as UTF-8 but as something else, that is all. That you can do echo £ using the console doesn’t prove anything, as that is handling input and output encoding the same.

    – deceze
    Jan 19 at 20:15













  • Perhaps there are two issues, but it doesn't explain why PHP silently fails when I throw an exception with a £ in the message. Removing it is caught by the catch block as expected.

    – thefuzzy0ne
    Jan 19 at 22:03
















0















Whenever I use PHP 7.2 to print a string to the console and it contains a unicode character to the console, it doesn't display correctly. For example, a £ displays as ┬ú.



It's not the console, as I can echo £ with no problem.



It's not the PHP version. Upgrading it the latest stable version or downgrading it down as far as version 5.6 does not fix it. I've used online emulators using the same versions and they don't have this problem, although they are outputting to a web page. However, it's irrelevant, because I know that this used to work in 5.6 and now does not.



The problem became apparent when I tried to catch an Exception which contained a £ sign in the string. Nothing would happen. The script would halt and no error would be displayed. It took me over an hour to discover that it had something to do with the £ symbol in the string which stops PHP dead in it's tracks, so the problem HAS to be PHP - I just don't know what.



Does anyone have any ideas as to what could be causing this?










share|improve this question













migrated from superuser.com Jan 19 at 18:07


This question came from our site for computer enthusiasts and power users.



















  • What OS is PHP running on?

    – grawity
    Jan 19 at 17:38






  • 1





    This has been a traditional problem in Windows but I think it's been fixed in 7.x versions. Are you on Windows 10? Can you see the error message if you print it to a file?

    – Álvaro González
    Jan 19 at 18:16













  • Sorry, I forgot to mention. I'm on Windows 7 Ultimate. It used to work fine. Something seems to have changed. I'm going to try it out on my other Win7 rig and see what happens. I suspect it will work fine.

    – thefuzzy0ne
    Jan 19 at 19:26











  • Your console is interpreting text not as UTF-8 but as something else, that is all. That you can do echo £ using the console doesn’t prove anything, as that is handling input and output encoding the same.

    – deceze
    Jan 19 at 20:15













  • Perhaps there are two issues, but it doesn't explain why PHP silently fails when I throw an exception with a £ in the message. Removing it is caught by the catch block as expected.

    – thefuzzy0ne
    Jan 19 at 22:03














0












0








0








Whenever I use PHP 7.2 to print a string to the console and it contains a unicode character to the console, it doesn't display correctly. For example, a £ displays as ┬ú.



It's not the console, as I can echo £ with no problem.



It's not the PHP version. Upgrading it the latest stable version or downgrading it down as far as version 5.6 does not fix it. I've used online emulators using the same versions and they don't have this problem, although they are outputting to a web page. However, it's irrelevant, because I know that this used to work in 5.6 and now does not.



The problem became apparent when I tried to catch an Exception which contained a £ sign in the string. Nothing would happen. The script would halt and no error would be displayed. It took me over an hour to discover that it had something to do with the £ symbol in the string which stops PHP dead in it's tracks, so the problem HAS to be PHP - I just don't know what.



Does anyone have any ideas as to what could be causing this?










share|improve this question














Whenever I use PHP 7.2 to print a string to the console and it contains a unicode character to the console, it doesn't display correctly. For example, a £ displays as ┬ú.



It's not the console, as I can echo £ with no problem.



It's not the PHP version. Upgrading it the latest stable version or downgrading it down as far as version 5.6 does not fix it. I've used online emulators using the same versions and they don't have this problem, although they are outputting to a web page. However, it's irrelevant, because I know that this used to work in 5.6 and now does not.



The problem became apparent when I tried to catch an Exception which contained a £ sign in the string. Nothing would happen. The script would halt and no error would be displayed. It took me over an hour to discover that it had something to do with the £ symbol in the string which stops PHP dead in it's tracks, so the problem HAS to be PHP - I just don't know what.



Does anyone have any ideas as to what could be causing this?







php unicode console






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 19 at 16:04









thefuzzy0nethefuzzy0ne

1437




1437




migrated from superuser.com Jan 19 at 18:07


This question came from our site for computer enthusiasts and power users.









migrated from superuser.com Jan 19 at 18:07


This question came from our site for computer enthusiasts and power users.















  • What OS is PHP running on?

    – grawity
    Jan 19 at 17:38






  • 1





    This has been a traditional problem in Windows but I think it's been fixed in 7.x versions. Are you on Windows 10? Can you see the error message if you print it to a file?

    – Álvaro González
    Jan 19 at 18:16













  • Sorry, I forgot to mention. I'm on Windows 7 Ultimate. It used to work fine. Something seems to have changed. I'm going to try it out on my other Win7 rig and see what happens. I suspect it will work fine.

    – thefuzzy0ne
    Jan 19 at 19:26











  • Your console is interpreting text not as UTF-8 but as something else, that is all. That you can do echo £ using the console doesn’t prove anything, as that is handling input and output encoding the same.

    – deceze
    Jan 19 at 20:15













  • Perhaps there are two issues, but it doesn't explain why PHP silently fails when I throw an exception with a £ in the message. Removing it is caught by the catch block as expected.

    – thefuzzy0ne
    Jan 19 at 22:03



















  • What OS is PHP running on?

    – grawity
    Jan 19 at 17:38






  • 1





    This has been a traditional problem in Windows but I think it's been fixed in 7.x versions. Are you on Windows 10? Can you see the error message if you print it to a file?

    – Álvaro González
    Jan 19 at 18:16













  • Sorry, I forgot to mention. I'm on Windows 7 Ultimate. It used to work fine. Something seems to have changed. I'm going to try it out on my other Win7 rig and see what happens. I suspect it will work fine.

    – thefuzzy0ne
    Jan 19 at 19:26











  • Your console is interpreting text not as UTF-8 but as something else, that is all. That you can do echo £ using the console doesn’t prove anything, as that is handling input and output encoding the same.

    – deceze
    Jan 19 at 20:15













  • Perhaps there are two issues, but it doesn't explain why PHP silently fails when I throw an exception with a £ in the message. Removing it is caught by the catch block as expected.

    – thefuzzy0ne
    Jan 19 at 22:03

















What OS is PHP running on?

– grawity
Jan 19 at 17:38





What OS is PHP running on?

– grawity
Jan 19 at 17:38




1




1





This has been a traditional problem in Windows but I think it's been fixed in 7.x versions. Are you on Windows 10? Can you see the error message if you print it to a file?

– Álvaro González
Jan 19 at 18:16







This has been a traditional problem in Windows but I think it's been fixed in 7.x versions. Are you on Windows 10? Can you see the error message if you print it to a file?

– Álvaro González
Jan 19 at 18:16















Sorry, I forgot to mention. I'm on Windows 7 Ultimate. It used to work fine. Something seems to have changed. I'm going to try it out on my other Win7 rig and see what happens. I suspect it will work fine.

– thefuzzy0ne
Jan 19 at 19:26





Sorry, I forgot to mention. I'm on Windows 7 Ultimate. It used to work fine. Something seems to have changed. I'm going to try it out on my other Win7 rig and see what happens. I suspect it will work fine.

– thefuzzy0ne
Jan 19 at 19:26













Your console is interpreting text not as UTF-8 but as something else, that is all. That you can do echo £ using the console doesn’t prove anything, as that is handling input and output encoding the same.

– deceze
Jan 19 at 20:15







Your console is interpreting text not as UTF-8 but as something else, that is all. That you can do echo £ using the console doesn’t prove anything, as that is handling input and output encoding the same.

– deceze
Jan 19 at 20:15















Perhaps there are two issues, but it doesn't explain why PHP silently fails when I throw an exception with a £ in the message. Removing it is caught by the catch block as expected.

– thefuzzy0ne
Jan 19 at 22:03





Perhaps there are two issues, but it doesn't explain why PHP silently fails when I throw an exception with a £ in the message. Removing it is caught by the catch block as expected.

– thefuzzy0ne
Jan 19 at 22:03












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54269930%2fphp-unicode-characters-not-displaying-correctly-in-console%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54269930%2fphp-unicode-characters-not-displaying-correctly-in-console%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]