
-Pwnt-
Veteran

Apr 10, 2006, 3:02 AM
Post #1 of 8
(758 views)
Shortcut
|
By reading this tutorial you should have the basic know how to execute small scripts on your php enabled servers. Note that I will not be explaining how to set up a web server + PHP. What Does PHP Stand For? PHP- Hypertext Preprocessor Starting & Ending Tags We start off by learning the 2 main tags that you must never forget, that is the starting and ending tags. Starting Ending Basic Syntax Now that you know about the starting & ending tags, let's start with a basic script.
<?php echo "This is my first php script!"; ?> So you have noticed echo, echo is simple, it outputs the text, "This is my first php script!", now you must end this with a semicolon. Why? The semicolon is a separator and is used to distinguish one set of instructions from another. Variables Now that you know some basic syntax let's start working on variables, variables are tons of fun and one of the most important parts of PHP.
<?php $myfirstscript = "This is my first php script!"; echo $myfirstscript; ?> So you have noticed $myfirstscript, I made the variable $myfirstscript that holds the string "This is my first php script!". Then of course just echoed the variable which would output "This is my first php script!". Comments Comments are also another important thing not only in PHP but all languages. They're used to disable any type of information inside them from actually executing with your script which of course would likely cause errors.
//This is a comment /*This is a comment block*/ Condition Statements Now these are fun to play with, they are used to execute certain codes on a condition.
<?php $mybrowser = "Fire Fox"; if ($mybrowser == "Fire Fox") { echo " You are using firefox!"; } else { echo " You are not using firefox"; } ?> So here I have set a variable equal to my browser then made a condition, if my browser is equal to firefox, output "You are using firefox" else (if your using something else) output "You are not using firefox". Of course this will not work until I add more to it but it gives you all a idea how condition statements work. Looping Looping is used for many many things, there are more then just one loop statement, I'll explain how to do the "While Loop".
<?php $z = 1; while ($z <= 5) { echo $z; $z++ } Again I made a variable named z with the value of 1, then stated while z is less or equal to 5 output the value of z increase z by 1 Which would output 1-5 on your page. Simple isn't it? Forms Now I'm assuming you have some basic understanding of html, although i will give an example of the html form but i will not be explaining it.
<form action="form.php" method="post"> Name: <input type="text" name="name"> <input type="submit" value="Submit"> That's the html form, very simple. Now to the fun part.
<?php $name = $_POST["name"]; echo "Hello ". $name; ?> Now here you have noticed something new and that would be "$_POST["name"]", $_POST is a variable already set by php, it received the information given in the html form, notice the name="name" in the html form and ["name"] in $_POST. Now this is the end of my small basic tutorial, you should now have the knowledge to execute simple scripts on your servers.
brb eating spaghetti
(This post was edited by -Pwnt- on Jul 29, 2007, 3:21 AM)
|