What you’ll need
In order to start writing PHP scripts, you need access to a Web server running PHP. Your main options are:
- Run PHP on your own computer: The easiest way to do this is to install a complete package likeXAMPP. This contains the Apache Web server, along with PHP and the MySQL database engine, in one easy-to-install package. XAMPP is available for Windows, Mac OS X, and Linux. (A popular alternative on Windows is WampServer.)
- IDE – Integrated Development Environment
- Adobe Dreameweaver
- Notepad++
- Zend Development Studio
- PHP Eclipse
Your first script
Here’s the PHP script that you’re going to create:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>My first PHP script</title> </head> <body> <p><?php echo "Hello, world!"; ?></p> </body> </html>
As you can see, most of this script is plain XHTML. The PHP code is inside the<?php
and?>
tags:
<
p
><?
php
echo "Hello, world!"; ?></
p
>
The <?php
and ?>
tags tell the Web server to treat everything inside the tags as PHP code to run. (Everything outside these tags is sent straight to the browser as-is.)
This line of code is very simple. It uses a built-in function, echo
, to display some text (“Hello, world!”) in the Web page. PHP contains hundreds of functions that you can use to write feature-rich applications.
Notice the semicolon (;
) after the PHP code — you need to put a semicolon after each line of code in your PHP scripts.
Note: The semicolon is optional if you’re only writing one line of code, as in this example.
Which of the following tags are acceptable ways to begin a PHP Code block?
- <SCRIPT LANGUAGE=”php”>
- <!
- <%
- <?php
- <?
0 comments:
Post a Comment