To write a PHP script, you can use any text editor such as Notepad, TextEdit, or Sublime Text.
Here is an example of a simple PHP script that displays “Hello, World!” on a web page:
<html> <head> <title>My First PHP Script</title> </head> <body> <?php echo "Hello, World!"; ?> </body> </html>
To save the file, you need to give it a .php extension. For example, you can save it as “hello.php”.
To run the script, you need to place it in a directory on your web server and access it through a web browser. For example, if you save the script in a directory called “php” on your web server, you can access it at “http://your-website.com/php/hello.php”.
You can also add PHP code to an HTML file by enclosing it within the PHP tags:
<html> <head> <title>My First PHP Script</title> </head> <body> <p>Today is <?php echo date("l, d M Y"); ?></p> </body> </html>
This script will display the current date on the web page.
In addition to the echo statement, you can use other PHP statements and functions to perform various tasks such as manipulating strings, arrays, and databases. You can also use conditional statements, loops, and error handling to control the flow of your PHP scripts.