Setting Up Your Development Environment


To create PHP pages, you'll need a text editor of some kind to create PHP files, which are a mix of HTML and PHP. All kinds of text editors are available on numerous operating systems that can serve the purpose, such as vi, emacs, pico, Macintosh's BBEdit or SimpleText, and Windows Notepad or WordPad. By default, PHP files are given the extension .php (as in myBigTimeWebPage.php).

The text you enter into our pages is just plain text, a mix of HTML and PHP. You can see an example in Figure 1-1; to create this PHP-enabled page, you just enter the text as it appears in the figure and save it as a file with the extension .php. As you can see, this example is mostly HTML; the PHP part is the script that appears between the <?php and the ?>. When you navigate to this document in your browser, the PHP-enabled server will read the document, find the PHP part between the <?php and the ?>, and execute it automatically. In this case, our PHP is just the single line phpinfo();, which will display an HTML table full of information about the PHP installation on the server, as we're about to see in "Creating Your First PHP Script."

Figure 1-1. Creating a PHP page with HTML in it.


NOTE

Windows WordPad has the annoying habit of appending the extension .txt to a filename if it doesn't understand the extension you've given the file. If you try to save a text document with the extension .php, WordPad will give it the extension .php.txt, which is very annoying. To avoid that, surround the name of the file with quotation marks when you save it, as in "logbook.php". Also note that by default, WordPad saves files in rich text format (.rtf) or as Microsoft Word (.doc) files, depending on your version of Windows. To make sure you save your XML documents in plain text format, select the Text Document option in the Save as type drop-down list box in the Save As dialog.


In fact, you can even use a word processor such as Microsoft Word to create PHP documents if you save your documents in plain text format, not in some other format such as .doc (for example, in Microsoft Word, you'd select the Text Only option from the Save as type drop-down list box in the Save As dialog). It's much better to stick with a plain text editor than a word processor, however, because unless you're careful, word processors will add all kinds of features and decorations that will get in the way.

You can also use a PHP integrated development environment (IDE) to create your PHP pages. IDEs give you all kinds of tools that simple text editors don't, such as checking what you've written automatically to make sure it's valid PHP, automatic syntax highlighting (where items such as PHP keywords appear in various colors, making it easy to pick out what's going on at a glance), and automatic deployment, where the IDE can upload your PHP pages to your ISP when you click a button or select a menu item.

Here's a starter list of IDEs available online that can handle PHP. Note, however, that most of them cost money, and although they have some nice features, we won't rely on those features in this book:

  • Komodo (www.activestate.com/Products/Komodo) runs on Linux and Windows.

  • Maguma (www.maguma.com) runs on Windows only.

  • PHPEdit (www.phpedit.com/products/PHPEdit) is free, but runs on Windows only.

  • Zend Studio (www.zend.com/store/products/zend-studio.php) runs on Windows and Linux. This one is created by the same people who created the Zend software "engine" that actually runs at the core of PHP itself.

If you're working with an ISP, you'll also need some way of transporting your PHP pages to the ISP, as you would with standard web pages. You can use a File Transfer Protocol (FTP) program or a web interface if one is provided by your ISP. If you haven't uploaded web pages before, ask your ISP support team what they recommend because they will often point you to an FTP program that they support or a web interface they've set up to allow people to upload web pages. You upload and run PHP pages just as you would standard HTML pages, as long as your server supports PHP.



    Spring Into PHP 5
    Spring Into PHP 5
    ISBN: 0131498622
    EAN: 2147483647
    Year: 2006
    Pages: 254

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