FAQ: Introduction to PHP - How is PHP Executed?

This community-built FAQ covers the “How is PHP Executed?” exercise from the lesson “Introduction to PHP”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn PHP

FAQs on the exercise How is PHP Executed?

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

So I was wondering why php code starts with <?php and ends with ?>.
Why the question mark? Wouldn’t it just look better without it, so why add it? Is there a specific reason for this?

Rasmus Lerdorf on implementing the first version of PHP “I wrote a very simple parser that would pick tags out of HTML files and replace them with the output of the corresponding functions in the C library.”

Maybe, but I highly doubt anyone really cares…

Besides, in pure PHP files, you’ll only find one <?php tag at the very top of the file.

In the views, we now mostly use template engines that make using the php tags obsolete.

Instead of <?php echo $variable; ?>, we’ll write {{ $variable }} instead.

1 Like

Why does PHP show <?php echo "I love PHP!"; on Codecademy?

However, in PHP website it shows <?php echo "I love PHP!"; ?>

Can someone explain please?

In a PHP-only file, there’s no need to provide a closing tag.


$hello = 'Hello, World!';

echo $hello;

It’s actually a PSR-2 recommendation to omit it:

The closing ?> tag MUST be omitted from files containing only PHP.

That said, within a HTML file, you’ll have to use the closing tag, otherwise the rest of the file would be treated as if it was PHP code.

So, for example:

  <h1><?php echo 'Hello, World!'; ?></h1>
  <p>This is a simple Hello World page.</p>

Hope this answers your question!


Even after doing as instructed, it still doesn’t show as it should.
I ran the same code on Codecademy after I deleted the closing tag and this is how the file looks in browser.
the quotation mark and semicolon of the php code are visible, how can I change that??
I even tried it on different browsers but it still shows the same result.

Hey there,

Could you please share some code so that we can check what might have gone wrong?

Thanks :slight_smile:

While learning HTML I would simply execute the code in any browser, but I just found out that for most programming languages you need to download a framework for it. In my case, I downloaded “xampp” and I have no problem now. Since I had no programming experience, I couldn’t have known that.
I hope this comment would be of help to a beginner who might find themselves stuck here too. :grinning:

Xampp is not a framework, xampp is a collection of tools

the browser (front-end) only understands html, css and JavaScript. PHP is a back-end language, so first the php files need to be parsed to a format the browser understands (html).

1 Like

Always annoying when you’re graded on following instructions rather than the actual output.

echo "I";echo "";echo "";echo "";echo " ";echo "l";echo "o";echo "";echo "v";echo "e";echo "";echo "";echo "";echo "";echo "";echo "";echo "";echo "";echo " ";echo "";echo "P";echo "";echo "H";echo "";echo "";echo "";echo "";echo "";echo "";echo "";echo "";echo "P";echo "";echo "";echo "!";

This is the output they asked for, and I’d rather it let me move on. Changing “Hello, world!” to “I love PHP!” does not, in fact, teach anyone PHP, and yet it’s the act of changing one sentence to another that we’re graded on.