PHP
PHP is a server-side scripting language which means that PHP scripts are executed on the server
PHP is an acronym for “PHP Hypertext Preprocessor”
PHP is enclosed in tags starting with <?php and ending with ?> as can be seen below.
<?php
?>
This can be repeated multiple times within a single web page.
How a Web server processes PHP files
When a browser looks at an HTML file it passes it to the browser
When a browser looks at a PHP (.php) file it passes it to the PHP processor on the server
When a browser finds a PHP opening tag (<?php) the web server hands the processing over to the PHP module.
The web server then assumes that all statements are PHP statements and until it encounters a PHP closing tag (?>).
When the web server encounters a PHP closing tag, it returns to HTML mode.
Suehring, Steve; Valade, Janet (2013-03-15). PHP, MySQL, JavaScript & HTML5 All-in-One For Dummies (For Dummies (Computer/Tech)) (Kindle Locations 7708-7717). Wiley. Kindle Edition.
Running a PHP File
A standard first PHP page will be to display that php is installed on the server. This will use a predefined function. The PHP script below will show the PHP information from the server.
Enter the code below and save it in your web server’s folder and run it as demonstrated by your teacher.
E.g. 127.0.0.1/phpinfo.php or localhost/phpinfo.php
FileName: Phpinfo.php
PHP Variables
Variables in PHP must:
Must begin with a dollar sign $
Should have a letter or symbol as the first character of its name.
The code below will assign two variables and then add them together.
The . operator is used to concatenate strings together.
The echo function is used to display content on the page. You will notice that we can use it to write HTML tags.