PHP Basics and Tutorials
Over the next month I will be taking some time a day to teach our users how to use PHP effectively for script installation. These will be basic courses geared to the new user of PHP. If you have any questions or comments concerning these PHP Tutorials please send us an comment to the bottom of the page. This tutorial will be basic and as time goes by we will add more advanced scripts and snippets to the content of this tutorial.
First we will start off with a simple “Hello World!” script.
To output a string, we will use PHP echo. You can place the variable inside the quotes, like we do below, in order to create a string which the echo function will output.
<?php echo "Hello World!"; echo "<h1>I love using PHP!</h1>"; ?>
In the example we output “Hello World!” without a problem. Make sure that we use proper HTML syntax!
The other echo statement we used echo to write a valid Header 1 HTML statement. In order to achieve this we simply put the “h1? tag inside the echo statement quotes. We are using PHP pages but we cannot forget to use HTML syntax as PHP will render HTML code also.
We cannot forget that double quotes are what PHP will recognize to open and close these statements. In order to have a good design and good website popularity by making your website have proper links, we will need to learn how to write them in PHP. If we happen to place a double quote in our statement we must escape the quotes using the following example:
<?php
echo “<a href=\”http://actionwerx.com/logos”>Logo Design</a>”;
?>
This will output as like this:
We must escape the quotes by using a backslash or by using an apostrophe ( ‘ )
Here is an example of echoing the variables:
<?php
$name = “Alex”;
$job = “programmer”;
echo “My name is “.$name;
echo “I am a “.$job;
?>
Because we did not break the line there this would show as:
My name is Alex I am a programmer
So what we need to do then is add some HTML in thereto fix the problem. Like so:
<?php
$name = “Alex”;
$job = “programmer”;
echo “My name is “.$name.”.<br>”;
echo “I am a “.$job.”.”;
?>
In order to add a string to an echo variable we added a period after closing the statement and before we opened it again. This will let PHP know that the string is there.
… “I am a”.$job.
