- slide 1 of 1
PHP is a programming language; moreover it is an interpreted scripting language. That means the code written using PHP is not compiled like many other languages but it is interpreted as it is executed. Much in the same way Perl is interpreted. The file we need to create to send to the interpreter is just an ordinary text file with PHP embedded.
Our PHP file does have a few requirements that we must follow. First whenever we are going to embed PHP code, we must enclose it with opening and closing PHP tags. Our opening tag will be: “?php”or “?”. And our closing tag will be: “?>”. We can have as many opening and closing tags as we need in our script. It’s best to break up embedded HTML with PHP inserted so we don’t generate an error by printing out the HTML. Plus this cuts time on the page execution since we don’t need to make the interpreter process and execute code that deals with printing the HTML.
Once we have created a PHP file, we need to save it with a .php file extension. This tells the server that the file is a PHP file and needs to be handled by the interpreter. If you have HTML in your PHP file, you’ll still need to save it with a .php file extension. Note that the file extension may be different for older PHP scripts written in PHP 3. On these older files, they may have the extension .php3, but will be processed by the interpreter just the same.
Once we have our PHP file all set the way we want, with HTML embedded and all of our PHP code in place we’ll need to upload the file to the web server. All PHP files need to be uploaded in ASCII format. Most modern FTP programs will do this automatically when they see the .php file extension on the file.
Also another thing about PHP files to keep in mind are the permissions of the PHP file. If you are on a Unix web server, you probably know about file permissions and how they work. When using a PHP file, you’ll need the file permissions set to execute so the PHP will be processed when the file is accessed.
PHP is used by many of today’s top web applications. I hope this PHP tutorial helps you when you start creating PHP files for you next top web application.