Open Source Web Development with LAMP Using Linux, Apache, MySQL, Perl, and PHP [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Open Source Web Development with LAMP Using Linux, Apache, MySQL, Perl, and PHP [Electronic resources] - نسخه متنی

James Lee, Brent Ware

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید










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


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()



/ 136