Problems in "Hello, world!" in PHP

Asked

Viewed 167 times

-1

It sounds funny, but it’s true. I made my first code in PHP and tested it, but it didn’t come out what I expected. See the image with the program windows used in this test.

inserir a descrição da imagem aqui

In short, I don’t know why instead of printing 1st > HW he printed HW"; ?> in Chrome. It seems that he plays <?php echo "1st > as an unknown code and prints what follows.

Additionally, I tested it in internet explorer and it only shows the file code, does not run it. After all someone can explain to me what I did wrong in this "hello world"?

  • 1

    Your Xampp is pretty outdated (apparently), the version you’re using is from 2015, maybe you’ve downloaded a version from an old or problematic source or maybe it’s an old computer from which you’ve tampered with something that made PHP stop working on Apache. From any recommend to install the link https://www.apachefriends.org/pt_br/index.html

  • 1

    Or, at the very least, disfigured, because Apache doesn’t seem to be interpreting your file with PHP. If you access the page’s source code, you will see that the PHP code is there the way you wrote it.

1 answer

4


Or did you disfigure the Apache on httpd.conf (because this version that uses Xampp is old, you may have done it and you don’t remember), or you nodepad.exe saved the document as Unicode or Unicode big endian:

notepad save as

This coding won’t work, save the documents as ANSI and then you should work normally.

I took the test myself, saved how Unicode big endian in a document containing the following content:

I also tested Unicode and the same occurred

Teste: <?php echo 'oi'; ?>

and tested:

Unicode big endian

When opening the view-source is displayed this:

view-source do Unicode big endian

In other words, the PHP interpreter cannot understand as if it were ANSI (or "approximate"), after saving as ANSI tested again and worked:

ANSI

Alternatives to nodepad.exe

Notepad.exe is very limited, today we have alternatives that can suit you better as the:

I left some suggestions Sublimetext with PHP settings:

  • 1

    You are right. The error is in the character setting of the text file. You cannot choose Unicode. But then the accentuation becomes difficult, from what I see. It’s a shame. Thank you for the answer.

  • @RHERWOLF on accents with Unicode, read the link I left in the reply: https://answall.com/a/43205/3635, save the document with "UTF-8 without BOM", configure the header, configure the mysql connection (if using). I recommend using Notepad++ or Sublimetext, with them you will be able to work better and with the tips I gave you will be able to use the accent.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.