Creating a PHP script is straightforward and similar to creating an HTML document. All that's required is a simple text editor such as Notepad or Wordpad (not Word) that can save a file as simple text (not rich text).
A PHP script is saved with a .php file extension instead of a .txt file extension and may consist of ...
PHP instructions on their own.
PHP instructions embedded with HTML elements and text content.
HTML elements and text content with no PHP instructions.
The last case is unlikely, although the PHP engine will not object, and the second case is the most usual.
In the case where the script consists only of PHP instructions and those instructions produce output then the script will automatically create an HTML header with HTML, head and body tags in place.
Not all PHP scripts produce visible output. For example a script might update fields in a database to act as a visitor counter.
To inform the web server where PHP instructions begin and end within the script, opening and closing tags are used with the instructions between.
<?php
...a list of PHP instructions
?>
Example of a PHP Script
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <head> </head> <body> Some content here <br>
<?php
...some PHP instructions
?>
</body> </html>
With any PHP script including the one above ...
The web server will pass the script to the PHP engine (because it has a .php file extension).
The PHP engine will parse the PHP instructions and write the results, if there are any, into the script then remove the PHP instructions and pass it back to the web server.
The web server will return the result to the browser as it would with an HTML file.