12.4 A Couple of Quick Examples


We'll start with two quick examples. Create a new directory for PHP work and cd into it:

 $  mkdir /var/www/html/php  $  chmod a+rx /var/www/html/php  $  cd /var/www/html/php  

Create a PHP file named hello.php : [4]

[4] Remember the permissions, 644 .

 <html>  <head>  <title>Hello, world! with PHP</title>  </head>  <body bgcolor="#ffffff">  <? echo "hello, world!" ?>  </body>  </html> 

To view the result of this file, load either one of these URLs: http://localhost/php/hello.php or www.opensourcewebbook.com/php/hello.php. The result can be seen in Figure 12.1.

Figure 12.1. hello, world! with PHP

graphics/12fig01.gif

The PHP code is embedded in the HTML within the <? ... ?> tag. In this example the PHP code simply echoes (displays) the string "hello, world!". The echo PHP statement outputs a string that eventually is rendered in the browser.

Now that the obligatory "hello, world!" example has been done with PHP, try a built-in function that does a lot of work: phpinfo() . Place this code into phpinfo.php :

 <html>  <head>  <title>PHP Information</title>  </head>  <body bgcolor="#ffffff">  <? phpinfo() ?>  </body>  </html> 

The function phpinfo() builds a page with a wealth of useful information on how PHP was built, the PHP environment, etc. To view the result, load either of these URLs: http://localhost/php/phpinfo.php or www.opensourcewebbook.com/php/phpinfo.php. The result of this can be seen in Figure 12.2.

Figure 12.2. PHP information with phpinfo()

graphics/12fig02.jpg



Open Source Development with Lamp
Open Source Development with LAMP: Using Linux, Apache, MySQL, Perl, and PHP
ISBN: 020177061X
EAN: 2147483647
Year: 2002
Pages: 136

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