PHP Syntax

   

PHP is a language that was designed to be easily embedded into HTML pages (although you don't have to do it that way). Most PHP pages have PHP code and HTML intermixed. When a Web server reads a PHP page, it is looking for two things to let it know it should start reading the page as PHP rather than HTML, the start and end PHP tags: <?php and ?>, respectively.

If you have configured your php.ini file to accept "short tags" (which are enabled by default), then you can use the syntax <? and ?> instead. Additionally, you can configure your php.ini file so that it accepts ASP style tags, <% and %>. This feature is turned off by default, and its only real purpose seems to be to allow certain HTML editors to recognize the in-between code as something other than HTML, in which case the editor won't mangle the code by imposing its own set of HTML syntax rules upon the code.

A brief example of PHP embedded in HTML:

 <h1>Welcome To The Web Site Of <? echo $company; ?>!</h1>  

The code above, when viewed via a Web server, simply prints out the name of the company in place of the PHP code.

In general, individual lines of PHP code should end with a semicolon, although it is not necessary to use semicolons if a beginning or an ending bracket is used (this will make sense when you look at if/then statements).

For example:

 <?  echo "<p>a line of code"; echo "<p>another line of code; ?> 

   
Top


Advanced PHP for Web Professionals
Advanced PHP for Web Professionals
ISBN: 0130085391
EAN: 2147483647
Year: 2005
Pages: 92

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net