Master Jake
Jun 14th 2009, 12:27 AM
Welcome to the installation and getting started sector for PHP.
First what you will need to do is download and install an apache server, we will use XAMPP.
To download XAMPP, visit http://www.apachefriends.org/en/xampp-windows.html and find the download link. If you don't have windows, find the XAMPP version for your operating system.
After downloading, double-click the installer for XAMPP and run through setup. Be sure that when it asks you, you choose to install Apache and MySQL. The other services (such as filezilla) will not be needed for our purposes, but you may install them if you wish.
Once you have finished installing XAMPP, double click the XAMPP Control Panel which should be on your desktop (unless you told the installer not to create the icon). In that case, navigate to the directory you installed the program and find it in there.
When the Control Panel is up, Click "start" by Apache and MySQL to get them up and running.
Next, you will need to locate your htdocs. Htdocs is the location in which Apache will use to run files for you (such as php). Navigate to the directory in which you installed XAMPP. You will see many folders in there. Find the htdocs folder and double click it. Inside htdocs you can place any php file (or other apache files such as .pl [perl] files if you install the perl interpruter).
Now, to make it easier on yourself, inside htdocs double click the xampp folder. Inside the xampp folder, create a new folder called "Projects". Next, right click it and "Send To Desktop (Shortcut)". This will create an easy shortcut for you to quickly access the projects folder where we will be storing our files.
Open up your internet browser such as Mozilla Firefox, Internet Explorer, Opera, or Safari for you Apple users. In the address bar, type in "localhost" and press return / enter. XAMPP will load up in the browser and automatically navigate to "localhost/xampp" which is the "htdocs/xampp" folder basically. Click on the end of the address, and add on "projects" to now make it "localhost/xampp/projects". Press return /enter. It will navigate to the projects folder we just made. Stay in here because we are going to be adding something in here in a moment.
____________________
NOW, to actually get started with the PHP part.
Open up your favorite text-editor. I will be using notepad, because notepad is for hardcore devvers and dreamweaver is for failures, remember that.
Every PHP file starts with the infamous php tags. These tags are a less-than sign (<), a question mark (?), and the letters php. The ending tags (because you must close all your tags), is a question mark (?) and a greater than sign (>).
Here is a preview.
<?php
// PHP CODE GOES HERE
// this is a comment
/* this is also
a comment
*/
?>
You will notice I have placed in some comments. Comments are basically lines of code that php will ignore when it executes. Use comments to write out "reminders" so you don't forget what each section of code does. This will be especially important when you start getting into much larger programs.
To make a comment in php, use a double foward-slash followed by whatever you want. Double foward-slash comments only effect the text that occurs after the slashes on that line. A multi-line comment, however, will effect all lines, until it is closed (similar to how php effects all input until its tags are closed with ?>).
A multi-line comment starts with a foward-slash asterisk (/*) and ends with an asterisk foward-slash (*/)
Here are both of the comments again.
// single comment
/*
multi
comment
*/
Too finish up our first php tutorial, I am going to be showing you how to write out text to the screen. It is extremely simple, all you need is the command "echo". Here is an example.
<?php
echo "Hello World";
?>
Now, let's go over this. We start our php tags, and type out echo with the text we want to write out in quotes (quotes are important for strings). Keep in mind that all php lines must end in a semi-colon (;) to insure the compiler knows the end of the line (as in most languages).
Write out the above code into your text-editor, save it as "anything.php" and drag it into your Projects folder. Next go to your internet browser, refresh the page "localhost/xampp/projects", you will see an Index of Projects screen come up with your project "anything.php" on it. Click that file and php will load the file and execute it. You will notice "Hello World" has been written out onto the screen.
____________________
Some final things that I will tell you is that if you wan't to use quotes (") in your text, you need to escape them. Escaping is basically telling the compiler to render the character(s) as ASCII and not part of the command. Since strings must be enclosed in quotes, how would you type anything in quotes between the strings without the compiler thinking that the second starting quote was actually the first ending quote.
To be simple, just use the backslash followed by the character you wish to escape.
For example, to escape a double-quote, use backslash double-quote (\").
Here is an example of this in action.
<?php
echo "Hello World. \"This text is in quotes.\"";
?>
Save and execute this code in your internet browser. The output will now be:
Hello World. "This text is in quotes."
I hope you enjoyed the first php tutorial. Next time we will go over variables.
Copyright (c) 2009 Jake Chappell. All rights reserved.
skateparkceasercash@yahoo.com
First what you will need to do is download and install an apache server, we will use XAMPP.
To download XAMPP, visit http://www.apachefriends.org/en/xampp-windows.html and find the download link. If you don't have windows, find the XAMPP version for your operating system.
After downloading, double-click the installer for XAMPP and run through setup. Be sure that when it asks you, you choose to install Apache and MySQL. The other services (such as filezilla) will not be needed for our purposes, but you may install them if you wish.
Once you have finished installing XAMPP, double click the XAMPP Control Panel which should be on your desktop (unless you told the installer not to create the icon). In that case, navigate to the directory you installed the program and find it in there.
When the Control Panel is up, Click "start" by Apache and MySQL to get them up and running.
Next, you will need to locate your htdocs. Htdocs is the location in which Apache will use to run files for you (such as php). Navigate to the directory in which you installed XAMPP. You will see many folders in there. Find the htdocs folder and double click it. Inside htdocs you can place any php file (or other apache files such as .pl [perl] files if you install the perl interpruter).
Now, to make it easier on yourself, inside htdocs double click the xampp folder. Inside the xampp folder, create a new folder called "Projects". Next, right click it and "Send To Desktop (Shortcut)". This will create an easy shortcut for you to quickly access the projects folder where we will be storing our files.
Open up your internet browser such as Mozilla Firefox, Internet Explorer, Opera, or Safari for you Apple users. In the address bar, type in "localhost" and press return / enter. XAMPP will load up in the browser and automatically navigate to "localhost/xampp" which is the "htdocs/xampp" folder basically. Click on the end of the address, and add on "projects" to now make it "localhost/xampp/projects". Press return /enter. It will navigate to the projects folder we just made. Stay in here because we are going to be adding something in here in a moment.
____________________
NOW, to actually get started with the PHP part.
Open up your favorite text-editor. I will be using notepad, because notepad is for hardcore devvers and dreamweaver is for failures, remember that.
Every PHP file starts with the infamous php tags. These tags are a less-than sign (<), a question mark (?), and the letters php. The ending tags (because you must close all your tags), is a question mark (?) and a greater than sign (>).
Here is a preview.
<?php
// PHP CODE GOES HERE
// this is a comment
/* this is also
a comment
*/
?>
You will notice I have placed in some comments. Comments are basically lines of code that php will ignore when it executes. Use comments to write out "reminders" so you don't forget what each section of code does. This will be especially important when you start getting into much larger programs.
To make a comment in php, use a double foward-slash followed by whatever you want. Double foward-slash comments only effect the text that occurs after the slashes on that line. A multi-line comment, however, will effect all lines, until it is closed (similar to how php effects all input until its tags are closed with ?>).
A multi-line comment starts with a foward-slash asterisk (/*) and ends with an asterisk foward-slash (*/)
Here are both of the comments again.
// single comment
/*
multi
comment
*/
Too finish up our first php tutorial, I am going to be showing you how to write out text to the screen. It is extremely simple, all you need is the command "echo". Here is an example.
<?php
echo "Hello World";
?>
Now, let's go over this. We start our php tags, and type out echo with the text we want to write out in quotes (quotes are important for strings). Keep in mind that all php lines must end in a semi-colon (;) to insure the compiler knows the end of the line (as in most languages).
Write out the above code into your text-editor, save it as "anything.php" and drag it into your Projects folder. Next go to your internet browser, refresh the page "localhost/xampp/projects", you will see an Index of Projects screen come up with your project "anything.php" on it. Click that file and php will load the file and execute it. You will notice "Hello World" has been written out onto the screen.
____________________
Some final things that I will tell you is that if you wan't to use quotes (") in your text, you need to escape them. Escaping is basically telling the compiler to render the character(s) as ASCII and not part of the command. Since strings must be enclosed in quotes, how would you type anything in quotes between the strings without the compiler thinking that the second starting quote was actually the first ending quote.
To be simple, just use the backslash followed by the character you wish to escape.
For example, to escape a double-quote, use backslash double-quote (\").
Here is an example of this in action.
<?php
echo "Hello World. \"This text is in quotes.\"";
?>
Save and execute this code in your internet browser. The output will now be:
Hello World. "This text is in quotes."
I hope you enjoyed the first php tutorial. Next time we will go over variables.
Copyright (c) 2009 Jake Chappell. All rights reserved.
skateparkceasercash@yahoo.com
