Starting with PHP

Just bump around recently with some students from a University nearby our home, though it is not yet part of their curriculum they are more than interested in the language. So I am going to write some simple tutorials regarding the language. The last time, I taught or mentor was very long ago, so this would be an exciting journey for me.

When PHP not yet existed?

If my memory serves me right, people do have the internet by 1995, most of the sites use CGI (Common Gateway Interface). If you need to fetch data from a database server, you would need to use the C language or Perl script. It’s a little bit hard to debug or develop since the need to spit out the information either to compile if it’s on C if it’s on Perl not many server log messages to pinpoint where the error is. You would see some servers have the cgi-bin folder that uses to house scripts that will interact with a Web browser. I think it has still today especially for most cPanel hosts.

Here comes PHP

PHP was written by Rasmus Lerdorf in C language. It was written in C because it was the language Rasmus was most comfortable with at that time. Unlike using CGI (Common Gateway Interface) the approach was to embed it with HTML, mostly just specifying with the file extension php. Basically, a scripting language that is executed on the server.

<!DOCTYPE html>
<html>
<body>
<h1>Heading</h1>
<p>paragraph.</p>
<?php
echo 'Hello world';
?>
</body>
</html>

The basic syntax of PHP is very similar to that of Perl, and both share several syntactic features with C. Whitespace is ignored in code, statements are ended with semicolons, and curly braces group together several statements into a single block. The name of the function is accompanied by the actual arguments, which are enclosed in parentheses and separated by commas.

<?php // all code starts with this tag 

// single statement
$variable = "Value of variable"; 

// sample function
function sample($argument, $argument2) {

}

// all code end with this tag
?>

The best way to learn a language is by using it. We would try to install PHP on a server or on a local development machine.

Share