PHP Basics

by 38 replies
44
Ok Well I am new hear but I have been doing programming for over 10 years.
I have been seeing a lot of post about learning php So I'll give some basics of php.

first you need a file called for example "index.php"
know for the php file to work you need to put this into it
PHP Code:
<?php

?>
so thats how you start your php file.

Ok Know we are going to make a basic call in your php file.
To start a basic syntax call it starts with $ sign. to enclose your value you can either use ' ' or " " know lets say your value text is hello it's me we in the word it's has a ' to void that value out you put \ this in front of ' this.
Know at the end of your syntax it has to have this ;
To print this value out you can either use print or echo to show your value out.
PHP Code:
<?php

$hello 
= 'hello it\'s me';
echo 
$hello;
print 
$hello;
?>
Ok so there is a very basic start.
So lets say you want to add a comment in your php file so you can come back to the file and read of what you doing you put this in front of your comment // for example.

PHP Code:
<?php
// this is how to print out our syntax
$hello = 'hello it\'s me';
echo 
$hello;
print 
$hello;
?>
Know lets say you have two strings you want to print out in one line this is how you do it. I like to make a new string that combines the 2 values.
So when you combine them after the fist value your going to want to put this behind it . yes the period.
PHP Code:
<?php
// this is how to print out our syntax
$name = ' and my name is joe';
$hello = 'hello it\'s me';
$hello_name = $hello.$name;
print 
$hello_name;
?>
So lets say you want to have a break in the value so it would print out like this
hello it's me
and my name is joe
your syntax would look like this you can see after the . we wrapped some html code in it to break it and inclosed with " " and after that we put another . so thats how we do that
PHP Code:
<?php
// this is how to print out our syntax
$name = 'and my name is joe';
$hello = 'hello it\'s me';
$hello_name = $hello."<br>".$name;
print 
$hello_name;
?>
Ok wel lets say that if value of some syntax is ted or joe and you want to print out the right value we can do this with the if statement. know the if statement looks like this
PHP Code:
if(){

} 
In these () is where your going want to put the value that either is equal or not equal to the value equal value is == not equal is =! so lets say value $a == '1' or in word terms this says $a is equal to 1. $a =! '1' word terms this says $a is not equal to 1.

this how it would look in the if statement
the equal
PHP Code:
if($a == '1'){

} 
the not equal
PHP Code:
if($a =! '1'){

} 
Know you see { } these that where you are going to put the data of what you want to show if the value is either equal or not equal.
PHP Code:
<?php
$a 
= '1';
if(
$a == '1'){
$b = 'what i want to print if $a is equal to 1';
}
print 
$b;
?>
lets put this in our hello php file

PHP Code:
<?php
// this is how to print out our syntax
$diff_name = 'ted';
if(
$diff_name == 'ted'){
    
$user ='Ted';
}
if(
$diff_name == 'joe'){
    
$user ='Joe';
}

$name = 'and my name is '.$user;
$hello = 'hello it\'s me';
$hello_name = $hello."<br>".$name;
print 
$hello_name;
?>
So I hopping your getting it so far

Know with the if statement you can have a else statement with it .
What that means in word terms is this if $a is not equal to 1 else use the other option.
so the php code would look like this
PHP Code:
<?php
$a 
= '1';
if(
$a == '1'){
$b = 'what i want to print if $a is equal to 1';
}else{
$b = 'what i want to print if $a is not equal to 1';
}
print 
$b;
?>
You can also have a if elseif else Statement

hear is a example:
PHP Code:
<?php
// this is how to print out our syntax
$diff_name = 'ted';
if (
$diff_name == 'ted'){
  
$user ='Ted';
  } elseif (
$diff_name == 'joe'){
  
$user ='Joe';
  }else{
  
$user ='Noname';
  }
$name = 'and my name is '.$user;
$hello = 'hello it\'s me';
$hello_name = $hello."<br>".$name;
print 
$hello_name;
?>
There is also another way you can do this Its called a switch where you add more values with out it becoming a head ache.So to call the switch it switch know case is the value you want it equal to break means it goes to the next one to find if equal to. You have a default if none of the values are equal to any of the case. So hear is a example of it

PHP Code:
<?php
// this is how to print out our syntax
$diff_name = 'ted';
switch (
$diff_name){
case 
'ted':
  
$user ='Ted';
  break;
case 
'joe':
  
$user ='Joe';
  break;
case 
'erica':
  
$user ='Erica';
  break;
default:
  
$user ='Noname';
}
$name = 'and my name is '.$user;
$hello = 'hello it\'s me';
$hello_name = $hello."<br>".$name;
print 
$hello_name;
?>
There some basics of php I hope that this helps
#programming #basics #php
  • Nice quick lesson here. Thanks
  • Such a good explanation for beginners
  • Thanks for share your knowledge. I am very interested to learn more about PHP. Its very useful for PHP beginner.
    • [1] reply
    • hey thank you I'll make more post on this and go into more detail about programming like function and classes I hope this helps alot of peps
  • Your information is very useful for human beings. Thanks for the nice information.
  • Banned
    [DELETED]
  • Banned
    Pretty good job.I love PHP by this perspective I can say ,your explanation is very effective for the beginner.Yuo can follow the book "beginner php 5-by wrox".I think it can strong your basic.
  • If you use php, you should have php manual
  • IF you want to really learn to go on that is the perfect way to learn .
  • Banned
    [DELETED]
    • [ 1 ] Thanks
    • [1] reply
    • Hey Friends this is my first post here but i want to share a resource which really helped me in learning php basics, hope it helps every newbie...
      thenewboston . org
      phpacademy .org

      as i am newbie so cant post link so just type it manually..
      i know this is gonna help everyone who is willing to learn php himself.

  • Go to youtube and search phpacademy channel. I learn much about php there.
    • [ 1 ] Thanks
    • [1] reply
    • PHP is a scripting language and many times used with HTML to compose functions that HTML absence. Any one who knows the basic of this programming language can easily learn the PHP.
  • Thanks Jiffy! I've used PHP but never knew the how and why. You may have prompted me to head off to "school" to learn it. Thanks also to Kaizen for the YouTube link.
  • Banned
    [DELETED]
  • Banned
    [DELETED]
  • I think it is good for all especially beginners they should see and learn from this post. Keep it up dear!
  • Very handy stuff for beginners. Especially those who are blindly struggling with filling out php templates for mobile sites.
    • [1] reply
    • I'd recommend the Larry Ullman PHP books
  • nice job
  • Banned
    [DELETED]
  • This is really awesome. You have really done a good job. Specially for the newbies who are interested in learning php to develop their web development skill.
    • [1] reply
    • You did fabulous job to giving me such a good information. That is as useful as important for all newbies. Who want to make them carrier on PHP? Thanks for your suggestion.
  • Banned
    [DELETED]
  • really good informative thanks to share.......
  • Banned
    [DELETED]
  • nice work man
  • Great stuff. And if your trying to learn php on your own computer locally it might help to get xampp to be able to write locally on your computer.
  • [DELETED]
  • You are done great job jiffyspop.These are the basic steps of php for beginner. I like your post very much..,I want to share some popular site of php learning W3Schools Online Web Tutorials , PHP Tutorial - Introduction and PHP: Hypertext Preprocessor are the best web site for learning php ..When you visit these sites you will learn soon php basic and much more about php..
    best regards ....
    sham
  • Decent, now lets advance everyone from basic PHP to basic Symfony.
  • I have designed some Websites with php for myself and my customers,PHP is a flexible and easy to learn programming language.
    • [2] replies
    • PHP is probably the most popular programming language on the web. Used to improve the website. With PHP, you can do things like create username and password pages, check details of a form, create forums, photo galleries, polls, and more. If you come across a website that ends in PHP, then the author has written some programming code to encourage plain, old HTML.
    • i agree with you
  • thank you for this thread
  • Really,it's good explanation of programming language .You are share nice and useful tutorial from other site are not provide.
  • Seems like people are really having a good time to get this helpful post from you. You really should carry on posting like this.
  • I am looking to start the programming but not getting what i have to do. I got your post it is a helping hand . Thanks i hope to read more about the php programming .
  • I'm really interested to PHP and I'm really happy to see this thread.
    Thanks for your kinda help. As a beginner , It's really important for mine.
    I have enjoy this one.
  • Hmm, for me this tutorial is a kid play.
  • I'm trying to learn php, thanks for your post
  • Awesome info seems, I am not from this but it has good feeling to me by seeing this.
    thanks for sharing this awesome one.
  • Thank you for sharing.
  • fine short course for a beginner
  • Nice one..
    W3schools.com is the best place to start, but I would recomend to have basic knowledge of html/css before moving to php.
    • [1] reply
    • Be careful when using W3 Schools:
      W3Fools

      They have a lot of WRONG content on their site.
  • Banned
    [DELETED]

Next Topics on Trending Feed

  • 44

    Ok Well I am new hear but I have been doing programming for over 10 years. I have been seeing a lot of post about learning php So I'll give some basics of php.