Site icon TestingDocs.com

PHP Script Syntax

Overview

In this tutorial, we will learn PHP Script Syntax in HTML documents. We can embed PHP Script into standard HTML web pages.

PHP Script Syntax

PHP script starts with <?php and ends with ?>.

<?php
?>

We can also use <? to start and ?> to end the PHP script.

<?
?>

Example

<!DOCTYPE html>
<!–
PHP Script Syntax Demo
–>
<html>
<head>
<meta charset=”UTF-8″>
<title></title>
</head>
<body>
<?php
//Sample PHP Code
echo “Hello, This page can run PHP code!”;
?>
<h1>PHP Tutorials </h1>
<h3>www.TestingDocs.com</h3>
</body>
</html>

Sample Output

Save PHP file with a “.php” file extension. For example, This tutorial uses “test.php”. PHP file should be deployed to the server in order to run. The exact path may vary from server to server. On Apache web server it is usually the htdocs folder. Deploy the file to the folder.

 

 

We can access the file from the web browser by typing the URL in the address bar.

http://localhost/test.php

The string localhost refers to the server running on your own machine. We can also refer to the local server is by using the loopback IP address: 127.0.0.1

http://127.0.01/test.php

The server runs on the default HTTP port 80. Incase the server runs on a different port we can append the port to the address. For example, if the server runs on 8080 port, we can access the URL as:

http://localhost:8080/test.php

PHP Tutorials

PHP Tutorials on this website:

https://www.testingdocs.com/php-tutorials/

More Information on PHP

https://www.php.net/

Exit mobile version