Skip to main content

Posts

Showing posts from December, 2017

Loops In php

Loops are used to run the same lines of code for multiple times. If we want to execute same code multiple times then we can put it into a loop block to avoid code repetition. Loop structure includes three sections. These are, Initialization  – To initialize the first iteration index of the loop. Conditional execution – For each iteration, it checks whether the specified condition is satisfied. If so, then only the code will be executed. Incrementation/decrementation – After processing each iteration, the loop index should be incremented or decremented to process next iteration. This will be continued till the loop condition is satisfied. PHP supports four types of loop statements. These are,  while ,  do…while ,  for and  foreach . In this tutorial, we are going to see about each of these types of PHP loop statements with an example. I have added a demo with  nested for loop  to print star triangle. view demo while The following example code shows a  while  loop with i

How to print result in PHP

In PHP there are various methods to print data. PHP provides more functions and language constructs for printing various data types. These functions are varied on the data format printed on the browser using them. For example, the print() and echo() statements prints string data, whereas, the  print_r()  is used to print compound datatype like arrays  or objects. In this tutorial, we are going to see some of the PHP functions that are used to create print statements. I have added the example code for each function. PHP Functions used for Printing Data print()  – The  print()  is used to create PHP print statement to print given data to the browser. It accepts single data and prints it on the browser. It is a PHP language construct and not a function. So, we can use ‘print’ without parenthesis for creating a print statement. The code shows an example for using  print  with and without parenthesis where both will print same data. print "Apple" ; //(or) print ( &

PHP opening Tags

PHP delimiters are nothing but the open close tags to enclose PHP script. PHP code can be parsed if and only if it is enclosed with these delimiters. There are various set of delimiters to recognize PHP code. These are as listed below. <?php … ?>  – It is most probably used delimiters and also preferable, since, PHP code enclosed with in <?php .. ?> could be recognized with other PHP servers independent of the tag related configuration directives. <script language=”php”></script>  – This will also work anywhere, like <?php … ?>. <? … ?>  – This is called as PHP short tags which will work based on the value set with  short_open_tag  directive of PHP configuration file. <?=..;?>  – This is also short form of denoting PHP code, but used as an alternative representation of PHP print statement. <% … %>  or  <%=;%>    – This is the delimiters for writing Active Server Pages(ASP) code. But it will be used for PHP code if and only

First Program in PHP-"Hello World"

After installing xampp  you are ready to start with php. This is our first blog through which you can learn php.  So let me start with the Hello World program in PHP. Following script displays the sentence “Hello, World!” in the browser. It is a simple and straight forward code. There are two basic ways of doing this hello world print and they are using ‘echo’ or ‘print’.  The difference between using ‘echo’ and ‘print’ is, the echo statement just prints the arguments passed to it and does not return any value. But the ‘print’ statement prints the argument as well as returns a value of 1. Since it returns a value, ‘print’ statement can be used in expressions. the echo statement can take multiple parameters and print statement takes only one parameter. Example Hello World Code using Echo <? php echo "Hello, World!" ; ?> Example Hello World Code using Print <? php print "Hello, World!" ; ?> In this context of printing ‘Hello,

PHP in Website Development Era

If you guys are watching this page its sure you want to check more about PHP.PHP language has a unique place in website development. It was introduced at a right time when web-based business was in new trend. Over a period it became one of the popular languages for creating web applications. The reasons are, simple language structure unique features  free license. PHP’s  unique features  lead to more popularity. Since 1994 when PHP development was started, we have seen the following version releases. PHP Versions Versions Key Features Description PHP/FI (1995) Form handling Perl/CGI script (PHP 1.0) introduced by  Rasmus Lerdorf . The Expansion is  Personal Home Page / Form Interpreter . PHP/FI2 (1997) Data conversion Form data export With slight modifications in Form Interpreter(PHP 2.0) to handle form entries. PHP  3 – (1998) PHP core is rewritten PHP parser is rewritten. Zend Engine is incorporated. Language core was changed by Zeev Suraski and Andi