1

Forgive me for the title. I am a beginner in programming, and I have two codes that do the same task, which is print the characters with ASCII values 240..255 in Windows Command Prompt. One is in PHP

<?php 
    for($n=255; $n>=240; $n--){ 
        echo chr($n);
    } 
?>

And the other in VBScript

For n = 255 to 240 Step -1
     WScript.Stdout.Write Chr(n)
Next

But the output characters are different. enter image description here

Why is that different? Is it because of character encoding thingy?

Poypoyan
  • 446
  • 6
  • 15
  • What encoding do you use?maybe to use utf-8 encoding? – dimis283 Dec 22 '16 at 14:24
  • I do not know how to get it, because I am beginner in programming. What I know is that in php.ini file, I only see "iso-8859-1" alongside with "encoding". Also, chcp in cmd gives 437 (if that helps). – Poypoyan Dec 22 '16 at 14:45
  • php header('Content-type: text/plain; charset=utf-8'); http://www.w3schools.com/php/func_xml_utf8_encode.asp – dimis283 Dec 22 '16 at 14:48
  • http://stackoverflow.com/questions/1453864/classic-asp-text-substitution-and-utf-8-encoding maybe useful for asp – dimis283 Dec 22 '16 at 14:54
  • Hmm... But are they the "same" characters (I mean in the picture), just different in encoding? – Poypoyan Dec 22 '16 at 15:24
  • 2
    The top one is Dos or OEM and the second is ANSI. Use Charmap under Windows Accessories to see. But there will be conversion and those characters in the second output will have been converted to Dos, so the first character goes from ANSI 255 to Dos 152 and that's what is showed to you. –  Dec 22 '16 at 22:56
  • @dimis283 why is this even remotely helpful? The OP is using a command prompt the process for encoding is completely different. – user692942 Dec 23 '16 at 09:01
  • What happens if you use `chcp 28591`? – user692942 Dec 23 '16 at 10:15
  • I want to ask different question, independent from what you see: What do you like to see as result? – Wernfried Domscheit Dec 23 '16 at 18:21
  • Also as VBScript is Unicode it has probably been converted Unicode to Dos. But US ANSI is the same as first 256 characters in Unicode. –  Dec 23 '16 at 22:23
  • Sorry for late reply. @Lankymart the VBSCript is now the same as in PHP :) . – Poypoyan Dec 26 '16 at 13:54
  • @Noodles thanks for explaining; I really need to learn more. – Poypoyan Dec 26 '16 at 13:55
  • @wernfried-domscheit Hmm... nothing, I am just experimenting... Thanks! – Poypoyan Dec 26 '16 at 13:55

0 Answers0