Thursday, January 4, 2018

Basic syntax of PHP


In order to write your PHP script, first you need to change the file extension of your webpage to “. php”. The PHP Engine parses only those files that have a “. php” extension. Now that you have your PHP page, the next step is to write the PHP code. 
             In a webpage, all the PHP code has to be embedded inside the opening “<? php” and closing ”? >” tags. Anything outside these tags is not parsed by the PHP engine and is rendered as is by the client.
 For Example(a) create a webpage with any name ending with extension “. PHP”. Open the page in text editor and enter the following code snippet in the page.

<! DOCTYPE html > 
< html >
 < head > 
< title > Example1 </ title >
 </ head
< body > 
< h1 > This will go as it is. </ h1 > 
<? php echo "This is parsed by PHP"; ?> 
</ body > 
</ html > - The Best Popunder Adnetwork

Place your web page in the “www” category of your WAMP server. Run your WAMP server , and enter the following URL on any browser : http:// localhost/[ xyz]. php (Replace “xyz” with the name of your page).

        The PHP tags indicate the parts of the page to be run through the PHP processor on the server. This leads to the third major difference. PHP scripts must be run on a PHP-enabled web server (whereas HTML pages can be viewed on any computer, directly in a browser). 
           This means that PHP scripts must always be run through a URL (for example, http:// page.php). If you’re viewing a PHP script in a web browser and the address does not begin with http, the PHP script will not work. 
         To make this first PHP script do something without too much programming fuss, you’ll use the phpinfo() function. This function, when called, sends a table of information to the web browser. 
          That table lists the specifics of the PHP installation on that particular server. It’s a great way to test your PHP installation and has a high “bang for your buck”quality.                         However, the phpinfo() function not only outputs a table of information, it also creates a complete HTML page for you. So this first PHP script does not require the standard HTML code, although subsequent scripts.

To create a new PHP script on your computer: 

1. Create a new PHP document in your text editor or IDE, to be named phpinfo.php 
            This first PHP script invokes a single PHP function.

1 <? php 
2 phpinfo(); 
3 ?> 

For this specific case, you’ll start with a blank file. But if your text editor or IDE has PHP file templates for you, you can certainly start with one of those.

 2. Begin the page with <? php on its own line. 
This opening PHP tag tells the server that the following code is PHP and should be handled as such. 
                   If your application has a PHP template , it may have created the PHP tags already. 

3. Add the following on the next line: 


The syntax will be explained in detail later, but in short, this is just a call to an existing PHP function named phpinfo. must use the opening and closing parentheses, with nothing between them, and the semicolon. 

4. Type ?> on its own line, as the last line. 

The closing PHP tag tells the server that the PHP section of the script is over. Again, because the phpinfo() function generates a complete HTML page, no HTML tags are needed. 

5. Save the script as phpinfo.php. 

Not to overstate the point, but remember that PHP scripts must use a valid file extension. Most likely you’ll have no problems if you save  files as filename.php.
          You also need to be certain that the application or operating system is not adding a hidden extension to the file. Notepad on Windows, for example, attempts to add .txt to uncommon file extensions, which renders the PHP script unusable. (Generally speaking, do not use Notepad.)


Just as a file’s extension on your computer tells the operating system in what application to open the file, a web page’s extension tells the server how to process the file: file.php goes through the PHP module, file.aspx is processed as ASP.NET, and file.html is a static HTML document (normally). The extension associations aredetermined by the web server’s settings.


If you’re developing PHP scripts for a hosted website, check with your hosting company to learn which file extensions you can use for PHP documents. In this book you’ll see .php, the most common extension.


You’ll occasionally see PHP’s short tags—simply <? and ?>—used in other people’s scripts, although I recommend sticking with the formal tags: <? php and ?>. Support for the short tags must be enabled on a server, and using them makes your code less portable.

PHP Page Rendering:-

When the client browser sends a request to the webserver for simple HTML pages, the server immediately sends the HTML for the page to the client, which is then rendered by the webpage. However, for PHP powered pages , the rendering mechanism is different.
      When a client sends a request for a page that contains PHP script, the page is first sent to the PHP engine for parsing. The PHP engine parses the script and returns the corresponding HTML , which is then sent to the client browser. This is because the client browser doesn’t understand PHP; it can only understand HTML markup.

Understanding the “echo” function :-

In Example(a) , we used the “echo” function, which is used to print plain text in a webpage . Whatever string is written after the “ echo” function is parsed by the PHP engine as plain text. You can also print HTML tags via the “echo” function which will be sent as is to the client browser. In Example (b), the list of eating foods has been displayed in the webpage using the “echo” function.


<! DOCTYPE html > 
< html > 
< head > 
< title > Example(a) </ title > 
</ head > 
< body > 
< h1 > Understanding PHP Echo </ h1 >
<? php echo "
< ul > < li > burgur </ li > 
< li > hotdog </ li > 
< li > sendwich </ li > 
< li > roll </ li > 
< li > egg roll </ li > 

</ ul >

"; echo "< h2 > The list of eating foods . </ h2 >"; ?> 
</ body > 
</ html >

In the above example(a), you can see that the syntax of the unordered list has been used as the parameter for the “echo” function. When the PHP engine parses this script, it will return the string as is to the webserver, which will be rendered to client as plain HTML. In the output, an ordered list containing the names of different eating foods will be displayed.

Displayed at output in WAP pages are :-

Understanding PHP Echo 

  • burgur
  • hotdog
  • Sendwich
  • roll
  • egg roll
The List of eating foods 

They are display in our WAP pages after run the program in computer. READ MORE


  1. It's a shame you don't have a donate button! I'd definitely donate
    to this excellent blog! I suppose for now i'll settle for book-marking and adding your RSS feed to
    my Google account. I look forward to brand new updates and
    will share this blog with my Facebook group. Chat soon!

    1. Thanks for comment anonymous I apologize I will work on fb page share thanks for suggestion you can share more social media my blog and you can subscribed , following my blog for daily update
      Have a nice day


Please comment and follow this site blog inbox