|
||||||||||||||
. . . . . |
Beginning PHP Programming
by Ron.
Get an account on FreePGS.com, and ask for a free upgrade to basic plus.
It's completely free. Remember PHP only works if your extension is .php or .php1 .php2 ... .php5.
<?php echo "Hello World!"; ?> That will print out the words Hello World! That isn't useful, but we're still on the basics. It uses the echo command to print those words and ends the command with a colon. That could also be accomplished by using print instead of echo. Code: <?php print "Hello World!"; ?>
Flash Tutorials in Video Format -
Watch them now at LearnFlash.com
We used the same technique with the quotations with only a different word.
Echo and print commands are basically the same thing. <?php $message = "Hello World!"; echo "$message"; ?> Notice that we put $message into quotations, and it printed out Hello World! See this is a cool thing about PHP. A variable can be displayed in quotes or without quotes and still work. With other scripting languages such as Macromedia's Action Script you would need to take it out of the quotes. You could do it that way too. Lets see what it will look like if we attached a couple variables with text. <?php $message = "great"; echo "I feel " . $message . " today!"; ?>That would be longer then just putting in... <?php $message = "great"; echo "I feel $message today!"; ?>
Am I right? Oh and you can also put HTML tags in the echo commands.
But if you use echo with the quotations then that might mess things up.
There are things called escape commands. Such as if you wanted to put in a
quotation without messing up the PHP script, then just put a backslash before it like... <?php echo "I have \$53,000 dollars in my bank account.<"; ?> Did you see how it was used? We had to escape the dollar sign so that the script wouldn't think that 53,000 was a variable and the html quotation marks.
Now lets have some fun.
Lets say you wanted to add another link to your nav. And you had 50 pages with that nav in plain HTML code. That would really stink, because you would have to change each of those files. You can make it much easier if you just broke up your pages intro structures. And stored those structures into template files. That means you change nav.tpl it would change your whole website's nav with that one file.
To do that, make call your structures: header.tpl nav.tpl body.tpl footer.tplThe header could contain your title, logo, ads, CSS, etc.. The nav would contain links, buttons, whatever. The body could contain blog, news, email, etc. The footer could contain copyright, etc..
Here's the code that could fix that problem of changing one thing. <?php include header.tpl ?> </td> </tr> <tr> <td> <table> <tr> <td> <?php include nav.tpl ?> </td> <td> <?php include body.tpl ?> </td> </tr> </table> <?php include footer.tpl ?>
That would be very nicely constructed.
<?php
if ($_GET['v'] == '') {
include home.tpl;
}
if ($_GET['v'] == '1') {
include games.tpl;
}
if ($_GET['v'] == '2') {
include toons.tpl;
}
if ($_GET['v'] == '3') {
include jokes.tpl;
}
?>
That code means if you go to index.php then the code will open the home.tpl file.
I would say that that is pretty sweet. I hope you learned something!
Well you're finally done! All you have to do now is try out some PHP on FreePGS.com and I bet you'll love it.
You can
find books on PHP
~RON |
|
||||||||||||
|
. | Home | Flash MX | Actionscript 2.0 | Flash 3D | Flash 8 | Flash Database | Flash Mobile | Flash CS3 | Java For Kids | Video Course | General Video | Photoshop | Web Design | Digital Photography | Games | free backgrounds | Resume | Streaming Video | Students Work | Links | Contact me | sitemap | reviews | . . |
||||||||||||||