In this beginners guide to PHP, I will introduce you to one of the best languages to build websites with. I’ve used it for several years with much success. I encourage you to read on, as this is not your typical technical tutorial.
PHP is a server side scripting language widely used in website development today. PHP stands for PHP: Hypertext Preprocessor. It is an Open Source Language that provides a way to build dynamic web applications.
Unlike HTML, and JavaScript, PHP is not visible in a site’s browser source code. It is known to have excellent security, scalability, and provides a powerful set of tools for web programmers.
It’s an alternative to ASP, JavaScript, Perl, C and other languages. The environment I usually work in is called LAMP. This means Linux, Apache, MySQL, and PHP. The first being the Operating System, the second being the Web Server, the third is the Database Server and the final is the Scripting Language.
Although it can be used on Windows Systems, and flexible enough for use in a wide variety of situations, this is the best combination to work with. PHP is also an Object Oriented Programming Language. For me, perhaps because of how my mind is wired, OOP is fantastic and smooth. It’s like legos.
Most web hosting companies provide PHP pre-installed and configured. So developers can start working right away. With that said, even the layman can start using it after hosting is setup.
Instead of naming your pages with an extension of .htm or .html, simply use .php. The document will still display the same way as if written only HTML.
Now, with your file types as .php, it opens up a whole new world, full of useful tools to build even better, more interactive web applications.
But don’t take this as an abandonment of other languages. HTML is still your best friend. It is still the framework of your visible website. PHP does a number of things to improve how we can use HTML. It provides enhanced options that compliment the HTML. It can spit out any of the HTML, or even JavaScript. It helps with file and image handling. Takes inputs and works hand in hand with the database server.
Code Demo
As a simple demo, and to quench the thirst of those who want to get into code; I will show you how to display a simple message with PHP.
Anywhere in a PHP document, PHP code can be placed. All PHP code is embodied by opening tags and closing tags. Just like in HTML. These tags are <?php and ?>. They are opening and closing tags respectively. In many cases you can just use <? and ?>.
To display some information to the screen, a simple function called echo or print can be used. To use this function, simply call it with a line like this:
<?php echo “Hello World”; ?>
Hello World is where your custom information would be. This will display “Hello World” where ever you placed it (without the quotations of course). A more simplified version of the line above is <?=’Hello World’?>. As you can see, this saves a little bit more space and is easier to deploy and manage.
Another simple demonstration, if that was just a teaser; PHP allows variables on several levels. I will just discuss a variable across any scope. A variable is like the shell of a peanut. It holds content.
In the Hello World example above, I showed how to print a line of text to the screen. This line of text is called a string. We can set the content of a variable to be the string. In other words, I can remove the nut from the shell and replace with something else. The variable is like the shell, and only the variable is handled after the content is set.
Also, we can also name our variable. In PHP a variable is named by using “$” then any random selection, starting with a lower case letter only and upper or lower case letters and numbers there after.
A variable can be declared, or made to exist by simply writing it out.
For example: <? $firstname; ?>.
This variable is not set with any content and would output nothing to the screen if used in our above example. We can set its content by writing <? $firstname = ‘Hello World”; ?>. Then somewhere else we can display our message like this; <?= $firstname ?>. Again very easy to deploy, the content can be as long as needed, be set in a more organized way, that does not upset the flow of your code.
It doesn’t matter if a variable is set somewhere else in the document, as long as it’s physically written above the point where it must be displayed. With loops (which I will do a separate article on) variables can be set after each loop. And it is OK to open and close the PHP tags and still transfer the information throughout the document.
Conclusion
This is just an introduction to PHP and how useful it can be. The point of variables is to hold and transfer information. Variables can be set with other variables, not just strings. In Dynamic web programming it is often necessary to use PHP to collect information from users, transfer and process that information for specific uses. Make it your friend.








Comments are closed.