Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Thursday, 27 February 2014

Do While Loops In Php

This tutorial is for Do While Loop.Now we had looked while loops that basically count to 10 and prints hello each time it is incremented. Do while loop is very similar to while loop,only a minor difference is that we don’t check whether condition is true or false or we don’t evaluate condition in start. Do while loop always runs the loop once.

Code for Do While Loop (Screenshot1):-

Do While Loops
Screenshot1

Output Screenshot2

Do While Loops In Php
Screenshot2
In this example we are using “do” keyword that will not check conditions but will perform whatever we tell to do and after that in while loop it will check condition. In above example, we have echo out in do loop “This will ALWAYS show” and in while statement we have false that condition.

Code for Do while loop (Screenshot3):-

Do while loops
Code for do while loops Screensot3

Output (Screenshot4):-

Screenshot4
In this example we are doing same thing as we did in while loops Examples .In this we are echoing out “This will ALWAYS show” 10 times where we set counter to start with value 1 and incremented it up-to value 10. If while loop condition get false it will always echo it out once by do loop. The main aim of using Do While Loop is that as it name refers it will first echo out once any statement/process declared inside “do statement” and only after executing that part it will move for executing “do statement” further on the basis of declared conditions in “while statement”.
Read More

Wednesday, 26 February 2014

While Loops in php

This tutorial is of While Loops. In php,why we need loops during programming ? Here we may repeat certain amount of actions for a specified amount of times.

 Code for While Loop (Screenshot1):-

While Loops in php
Screenshot1

Output (Screenshot2) :-

while php
Screenshot2


In this example we have echoed out “Hello” by while loop.In this loop 1 evaluates true which echo out “Hello” but what if we want to echo out “Hello” 100 times! Let see example,how to echo out “Hello” for 10 times.

Code for While Loop (Screenshot3):-

Code for while loops in php
Code for while Loops Screenshot3

Output (Screenshot4):-

php while code
Screenshot4
In this example, we have starter counter which initialize/starts loop and condition counter which must be less than or equal to 10 that will be incremented again and again upto the limit of condition counter and thus echo out “Hello” 10 times.

Code for While loop (Screenshot5):-

While Loops
Screenshot5

Ouput (Screenshot6) :-

loops
Screenshot6
In this example condition will false and will not display “Hello” because condition counter is greater than 10.
Read More

Sunday, 16 February 2014

Concatenation in php

concatenation
"Con","cat","en","ation"
This is tutorial for concatenation within php. Now if you ever come across working with concatenation you will come to know about it in a better way.Before programming you may understand how to concatenate different variables together.Later on, How to printvariables which are concatenated in,Its very very simple in php.

Code for Concatenate in php (Screenshot1):-

Concatenation in php
Concatenation in php Screenshot1
 <?php

$day = 'Thursday';

$date = 31;

$year = 2011;



echo 'The date is '.$day.' '.$date.' ' .$year;

?>

Output (Screenshot2) :- 

Concatenation in php
Screenshot2
 In this code of  concatenate in php I am creating three variables i.e. $day, $date, $year.Now to echo one or more variables we have to join variables with dot which is called as concatenate. In single quotation (‘) inside echo statement we are echoing variables and text.Blank single quotation (‘) is used to leave space between variables.With Single quotation (‘) concatenate feature is most useful and with Double quotation (“) too its easy which I will so you in later tutorials.

Code For Concatenate in php (Screenshot3):-

Screenshot3

<?php

$day = 'Wednesday';

$date = 30;

$year = 2011;



echo 'The date is '.$day.' '.$date.' ' .$year;

?>

Output (Screenshot4) :-




In this examples i just updated variables and its automatically update output.So this is harder but fastest way to echo out variables by concatenate in string data.

Code for concatenate in php (Screenshot5):-
Concatenation in php
 Screenshot4


In this examples i just updated variables and its automatically update output.So this is harder but fastest way to echo out variables by concatenate in string data.

Code for concatenate in php (Screenshot5):-

 
concatenation in php
Screenshot5

<?php

$day = 'Wednesday';

$date = 30;

$year = 2012;



echo 'The date is <strong>'.$day.' '.$date.' ' .$year.'</strong>;

?>


Output (Screenshot6):-

concatenation in php
Screenshot6

In this example i am including html tags strong tag with concatenate strings, variables and also html tags.In this code it will bold variables.

Code for Concatenate in php with Double quotation marks(Screenshot7):-

Concatenation in php
Screenshot7

<?php

$day = 'Wednesday';

$date = 30;

$year = 2011;



echo "The date is $day $date $year";

?>



Output (Screenshot4) :-

Concatenation in php
Screenshot4

In this example we used Double quotation marks to concatenate string and variables and its easy because here you don’t write any dot (.) or to leave space in single quotation marks. Its very easy to Concatenate with double quotation marks.But single quotation marks are faster.Concatenate looks complex code in understanding there so i am recommending to always use single codes.

Code for Concatenate in php (Screenshot8):-

Concatenation in php
Screenshot8

<?php

$day = 'Wednesday';

$date = 30;

$year = 2011;



echo 'The date is $day $date $year';

?>

output (Screenshot9):-

Concatenation in php
Screenshot9
In this code if we use single quotation mark without concatenate with dot (.) it will echo variable name and does not reference to variable values.
Read More

Thursday, 13 February 2014

Variables in php

php variables
Variables
This tutorial is for variables. If you have worked with any other programming language you know what are variables for and what they will do.Values are assigned to variables and variables are of different types.Now in this tutorials i am going to show you how to declare variables by assigning values to standard structure and then variables are echoed out on the browser.So, Usually in programming languages such as JavaScript or for any other language like it we have to use keywords,for example in java we use “var” like var example.





<?php

var name = 'value';

?>



In php we don’t need any keywords to define anything only we need to assign it with “$” dollar sign notation and afterwards we can assign “_” sign or characters or strings or numeric characters also. Assigning can be done in upper-case and lower-case both.
Code for Variables(Screenshot1) :-

Variables
Code For Variables Screenshot1


<?php

echo $text = 'Hello World.';

echo $number = 100;

?>



output (Screenshot2) :-

Code for Variables
Screenshot2


In Screenshot1 you can see codes for string.I have used sign ” notation for numeric value and i am not using any notation but only semi colon “;” . Semi colon “;” is a separator. Echo statementecho’s out the variables.We can assign any value to variables such as floating values, Boolean values,etc., but this we will see later on in if statements.

Code for variables different way (Screenshot3) :-

Variables in php
Code for Different types for variables Screenshot3


<?php

$text = 'Hello World.';

$number = 100;

 echo $text;

?>


Output (Screenshot4) :-

code for variables in php
Variables Screenshot4

It will only echo variable $text contain because we only echoing $text variable Code for variables different way second example (Screenshot5):-

Screenshot5


<?php

$text = 'Hello world.";

$number = 100;

echo $number;

?>

Output(Screenshot6) :-

Variables string
Screenshot6


It will echo out the content of variable $number because we are echoing variable $number. Programming languages are used todeclare different data’s, for example you want to take users age or take users name or anything you need to declare,so either you will store it as string data or you will store it as numerical data like integers (similarly for floats),which is somewhat tedious ! But, I would like to tell you an important aspect of php , that you don’t need to think about what data you are storing, you just simply need to assign “$” Sign in the prefix of variable name following with equal to and the variable value. Declaration of variables in php is quite easy.

Read More

Embedding PHP Inside HTML

Embedding PHP Inside HTML
Embedding PHP Inside HTML
This is a tutorial i am going to talking about embedding PHP Inside HTML. Now embedding is paying something within something embedding insides. lets see example

Code for simple html form with php file extension (screenshot1):-


Code For Simple Html From With Php File Extension Screenshot1
<input type="text" value=" Hello World.">

output (Screenshot2) :-

Embedding PHP Inside HTML
Screenshot2
you will see a small text-box with echo hello world. Now in another example i will embedding php code with html by using variables of php and in values of html form i will use standard variable for string lets see how it will happens

Code for embedding PHP Inside Html (Screenshot3):-

Code for embedding PHP Inside Html
                         Code for embedding PHP Inside Html Screenshot3


<?php
$text = 'Hello World.';
?>
<input type="text" value="<?php echo $text; ?>">

Output (Screenshot4):-


Embedding PHP Inside HTML
Screenshot4
In Advance php you have to use dynamic forms and so its good example for start-up  now in this $text is the variable which is string Hello world. and in html code we had called $text which is string Hello world. its pretty easy. variables also use in database , static text etc. Its very useful in php. variables are declared with ($) sign. and at end use “;”. and when you write php code u can write in one line or multiple line there is same effects. for example

you can use this code also for same result (screenshot4) :-

<?php
$text = 'hello world.';
?>
<input type="text" value="<?php
echo $text;
?>
">
Read More

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates