Jump to content
xisto Community
Spectre

Php - The Basics Learn the basics of PHP

Recommended Posts

this is a really good start up guide for php noobie like me ... after reading this ... i have got some clue what php is about and i know i will try to learn php more in the future ... a pretty good guide for beginners ^_^

Share this post


Link to post
Share on other sites

This is WAY too long for me to sit back and read all this.

Share this post


Link to post
Share on other sites

If you think that is to long try reading books about it. I had one question. In the If or esle statement can you have more then one if likeIfIfElseI no that isnt the correct code but would it work to have more then one If

Share this post


Link to post
Share on other sites

Yes. You can have has many if statements contained within each other as you like. However, it may be easier simply to be more specific with the original condition.

// Multiple If() statements:if( condition1 ) {  if( condition2 ) {    if( condition3 ) {      if( condition4 ) {        echo 'Something';      }    }  }}// A simpler way:if( condition1 && condition2 && condition3 && condition4 ) {  echo 'Something';}

I should get around to writing more on this some time - probably around mid November when everything else is wrapped up. Thanks to all those who have commented (both positive and negative constructive feedback is appreciated).

Share this post


Link to post
Share on other sites

Yes. You can have has many if statements contained within each other as you like. However, it may be easier simply to be more specific with the original condition.

 

// Multiple If() statements:if( condition1 ) {  if( condition2 ) {    if( condition3 ) {      if( condition4 ) {        echo 'Something';      }    }  }}// A simpler way:if( condition1 && condition2 && condition3 && condition4 ) {  echo 'Something';}

I should get around to writing more on this some time - probably around mid November when everything else is wrapped up. Thanks to all those who have commented (both positive and negative constructive feedback is appreciated).

198375[/snapback]


I mean like If condition one or If condition 2 or If condition 3 then something then else something

Share this post


Link to post
Share on other sites

If condition OR condition2 etc is....

if (condition1 || condition2) {    performThis(); // Sample function} else {    performThisInstead(); // Sample function}

And you can combine the two...

if ((condition1 || condition2) && (condition3 || condition4)) {    performThis(); // Sample function} else {    performThisInstead(); // Sample function}

Share this post


Link to post
Share on other sites

Notice from BuffaloHELP:
Merged two topics for two different tutorial approach. Please search the forum before making a new topic.

 

Im not sure if this is supose to go in the programming forum or here , this said "Tutorials" so ive decided here , if im wrong you may move it or delete it :)

 

---------------------------------------------------------------------------------------------------------------------------

 

I figured it's time to make a small tutorial , by reading this tutorial you should have the basic know how to execute small script's 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 tag's that you must never forget , that is the starting and ending tag's.

 

Starting

<?php
Ending
?>
Baisc Syntax

 

Now that you know about the starting & ending tag's , let's start with a basic script.

<?phpecho "This is my first php script!";?>
so you have noticed echo , echo is simple, it output's the text "This is my first php script!" , now you must end this with a semicolon , why? the semicolon is a seperator 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 ton's of fun and one of the most important part's of PHP.

<?php$myfirstscript = "This is my first php script!";echo $myfirstscript;?>
So you have noticed $myfirstscript , i made the variable $myfirstscript that hold's the string "This is my first php script!" . Then ofcourse just echo'd 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 , there used to disable any type of information inside them from actually executing with your script which ofcourse would likely cause error's.

//This is a comment/*This isacomment block*/
Condition Statements

 

Now these are fun to play with , they are used to execute certain code 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" . Ofcourse this will not work untill i i add more to it but it give's you all a idea how condition statements work.

Looping

 

Looping is used for many many thing's , there are more then just one loop statement, ill 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
while ($z <= 5)
output the value of z
echo $z
, increase z by 1
$z++
. Which would output 1-5 on your page. Simple isn't it?

Forms

 

Now im 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 recieved the information givin in the html form , notice the name="name" in the html form and ["name"] in $_POST.

 

Now this is the end of this small basic tutorial , you should now have the knowledge to execute simple script's on your server's

 

If you wish to learn more about PHP you may visit some links to tutorial's i will provide you below.

 

PHP.Net - Recommended

W3Schools - Recommended

Edited by BuffaloHELP (see edit history)

Share this post


Link to post
Share on other sites

Good explanation. Some comments:

 

This code:

 

<?php$mybrowser = "Fire Fox";if ($mybrowser == Fire Fox) { echo " You are using firefox!"; }    else { echo " You are not using firefox"; }?>

Should be:

 

<?php$mybrowser = "Fire Fox";if ($mybrowser == "Fire Fox") { echo " You are using firefox!"; }    else { echo " You are not using firefox"; }?>

With the quotes around if ($mybrowser == "Fire Fox") {

 

Otherwise, you'll get an error like:

 

Parse error: parse error, unexpected T_STRING in /home/xxxxxx/public_html/xxxxx.php on line XX

Share this post


Link to post
Share on other sites

woW,it is really an awesome tutorial.although i know PHP not bad,i'd like to learn some from here unobtrusively...to be continue...this topic

Share this post


Link to post
Share on other sites

this is a very weird tutorial, concidering it's just rehashing what's in the manual. It might be more interesting to write a bit of code and go over the logic for it instead of going over functions & stuff.round.

Share this post


Link to post
Share on other sites

its a very completed language, covering the most wide aspects and possibilities of weblanguage, you may say that for example ASP is another great language, but my experience with that is the slowness of the language. I have never had wellmade pages that actually loaded instantly, while doing the exact same thing in PHP gives me instant pages.The language is dynamic, fast and is very well-understandable for both beginners as experts, aswell as it being a great challenge to anyone.Besides of that. the PHP community is one of the most friendly communities i have ever come across with, together with Xisto of course :lol:People help you if you help them. People support you as much as they can and try their best to keep the community a great place for everyone. No question is weird or wrong and that is the key to being a successful community!

Share this post


Link to post
Share on other sites

its a very completed language, covering the most wide aspects and possibilities of weblanguage, you may say that for example ASP is another great language, but my experience with that is the slowness of the language. I have never had wellmade pages that actually loaded instantly, while doing the exact same thing in PHP gives me instant pages.

 

The language is dynamic, fast and is very well-understandable for both beginners as experts, aswell as it being a great challenge to anyone.

 

Besides of that.  the PHP community is one of the most friendly communities i have ever come across with, together with Xisto of course :lol:

 

People help you if you help them. People support you as much as they can and try their best to keep the community a great place for everyone. No question is weird or wrong and that is the key to being a successful community!

205253[/snapback]


Very well said , couldn't of said it any better :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.