Combining PHP and HTML – Code with examples

Write the following code, inside a new file created with our favorite editor, making sure to save it with a name whose extension is .php, for example: hello.php.

Combining PHP and HTML – Code with examples | Learn PHP & MySQL | Write the following code, inside a new file created with our favorite editor, making sure to save it with a name whose extension is .php, for example: hello.php

The key concept: completing the HTML pages inmediately

We are going to create, try and try to understand our first PHP code

  • Write the following code, inside a new file created with our favorite editor, making sure to save it with a name whose extension is .php, for example: hello.php

This will be the code of hola.php:

<html>
<head>
</head>
<body>
<p>This was written in HMLT</p>
<?php
print (“<p>Hello world! This was written by the PHP interpreter </p>”);
?>
</body>
</html>

This file must be saved inside the root folder of the Web server that we have installed.

  • • We turn on the local server software

The Web server software will be waiting for you to request, through a browser (Explorer, Firefox, Opera), any of the files you have ready to serve us. In this case we will ask for the file hola.php

  • To do this, we will open the browser and write the necessary URL to request the Web server the file hola.php. This is a key issue

On a PC with a local Web server we must write:
http://localhost/ejercicio1/hola.php
or using the local IP address
http://127.0.0.1/ejercicio1/hola.php

Attention:

It will not work to go to the File menu à Browser file, since our PHP file needs to be processed by the PHP interpreter program installed on the Web server, which should be on.

It also does not work for those who have Dreamweaver, press F12, for the same reason. Nor does it work to double-click the PHP file.

In all those erroneous cases, if you look at the URL, it will not mention anywhere http: //localhost/ejercicio1/hola.php. For this reason, the Web server software and the PHP interpreter will not process that file.

Once requested the URL of the file from our browser, and after waiting a few seconds, the source code that was processed on the server will arrive to the browser. From this moment, in which the generated code arrived at our browser, we can access the source code that was delivered to our browser (using the menu: View à Source code) and, in this example, we will see that what has arrived following:

<html>
<head>
<title>Hola</title>
</head>
<body>
<p>Esto estaba escrito en HMLT</p>
<p>Hola mundo! Esto lo escribió el intérprete de PHP</p>
</body>
</html>

Which means: the PHP interpreter erased all the orders that it found between the marks <?php and ?>, Which are the ones that indicate the beginning and the end - respectively - of an area in which the PHP interpreter is going to be given orders and, instead of what he had written there, he wrote, using the print function, the text:

<p>Hello world! This was written by the PHP interpreter </p>

🤖

ChatGPT Free
Ask questions on any topic

CITE ARTICLE


For homework, research, thesis, books, magazines, blogs or academic articles

APA Format Reference:

Delgado, Hugo. (2019).
Combining PHP and HTML – Code with examples.
Retrieved Apr 25, 2024, from
https://disenowebakus.net/en/combining-php-html

Participates!

Share it with your friends in Social Networks!

Professor at the University of Guadalajara

Hugo Delgado Desarrollador y Diseñador Web en Puerto Vallarta

Professional in Web Development and SEO Positioning for more than 10 continuous years.
We have more than 200 certificates and recognitions in the Academic and Professional trajectory, including diploma certificates certified by Google.

CONTINUE LEARNING

IT ALSO DESERVES TO PAY TO VISIT:

Not finding what you need?

Use our internal search to discover more information
Related content:

Would you like to learn more about Web Design?

Meet all the courses and tutorials that we have for you completely free
Learn Web Design
 

Leave your Comment

SPONSOR

Your business can also appear here. More information

Your browser has blocked advertising.
Please 🙏 allow to visualize the announcements to be able to access, thank you.