Access_Denied's Forums

Site Resources => Tutorials => Topic started by: Access_Denied on August 16, 2007, 04:15:01 AM



Title: Tutorial One: Introduction to PHP
Post by: Access_Denied on August 16, 2007, 04:15:01 AM
Welcome to my PHP programming tutorial. The reason why I'm doing PHP is because it's so closely related to C/C++. It's also a very powerful language, and very useful to know, as almost all websites are coded in PHP. Now, PHP is a web scripting language, used to code more complex websites, like these forums. But, if you right-click and view the source of this page, you don't see PHP, you see HTML. That's because when you access a page, the PHP engine on the server first converts the page to HTML, then sends it to your browser. That's because your browser doesn't read PHP, it reads HTML. So if you right-clicked on a PHP file, and chose to open it with a browser, it wouldn't do anything. OK, now you know what PHP is, and what it's used for, so let's get started on the syntax.

In any file, all your PHP code will reside between these tags:

<?php
code code code
?>

Note, that this can be a plain PHP file, or it can contain HTML, like this:

<html>
<body>
<?php
code code code
?>
</body>
</html>

But, no matter what type it is, the file always has a .php extension, not a .html extension. Also, like HTML, C, Lua, and many other languages, PHP ignores whitespace. So if you have a line of code, then twenty  blank lines, then more code, it will ignore the twenty blank lines as if they weren't there. So, what do you say we write a quick piece of starter code?

<?php
echo "This is sample code<br>";
echo "Hello There";
?>

Now, quick explanation. echo is used for printing things. The <br> tag is in there to stand for a newline. And, also note you must use semicolins. Anyway, that's all until the next tutorial, where we'll learn about variables.

EDIT: Almost forgot to tell you how to test your code. First, go to wampserver.com and install it. Then go into C:\wamp\www. (Assuming you installed it into that location.) Then, create a file called index.php. Write your code in there. Now, go to your browser, and type 'localhost' into the address bar, without the quotes. You've just created a webpage that's being run from your computer. If you want other people to view your webpage, they need to type your IP address into the address bar. To get your IP, go to cmyip.com. Anyway, that's how you test a PHP file.


Hosted by www.Geocities.ws

1