Chapter 12. Using PHP Features

Using PHP Features

Chapter at a Glance

PHP is a powerful scripting language that is platform independent. As long as your host has PHP installed on your server, you can use it regardless of server type. When a browser requests a PHP page, the PHP script is executed on the server and the resulting HTML is sent to the browser. PHP pages may contain text, HTML, and script blocks, and offer similar functionality to Legacy ASP pages.

Microsoft Expression Web 2 provides several tools to make working with PHP easier and also assists the user in creating and previewing PHP files. Programming in PHP is a very broad topic and is outside the scope of this book.

In this chapter, you will become familiar with the tools that come with Expression Web 2 and how to use them. You will learn how to create a PHP page and convert an HTML page to PHP. You will also learn how to work with PHP functions, variables, and includes in Expression Web 2. At the end of the chapter, you will find references to more information about programming in PHP.

Important

Important

Before you can use the practice files in this chapter, you need to install them from the book’s companion CD to their default location. For more information about practice files, see "Features and Conventions of This Book" at the beginning of this book.

Troubleshooting

Graphics and operating system–related instructions in this book reflect the Windows Vista user interface. If your computer is running Windows XP and you experience trouble following the instructions as written, please refer to the "Introducing Expression Web 2" section at the beginning of this book.

To improve the readability of the graphics in this book, Expression Web 2 was set to use the Windows color scheme instead of the default Expression Studio 2 color scheme.

Setting Up PHP

In order to preview PHP files and execute the PHP code on your local computer, you must install PHP.

In this exercise, you will install PHP on your local computer and set it as an option in the Expression Web 2 Development Server.

Note

Setting Up PHP

USE the CH12 sample site. This sample site is located in the DocumentsMicrosoft PressExpression Web 2 SBSSample Sites folder.

BE SURE TO start Expression Web 2 before beginning this exercise.

OPEN the CH12 site by clicking Open Site on the File menu.

  1. Go to php.net/downloads.php, and under the Windows Binaries heading, download the latest PHP.zip file. In the Download File dialog box, click Save. Then, in the Save As dialog box, browse to the location of your choice.

    Setting Up PHP
  2. Right-click the downloaded folder, and then click Extract All.

  3. In the Extract Compressed (Zipped) Folders dialog box, click Browse. In the Select a destination dialog box that opens, select the drive C location, and click Make New Folder. Then create a folder named PHP.

    Setting Up PHP
  4. Click OK in the Select a Destination dialog box. Then in the Extract Compressed Folders dialog box, click Extract.

    All of the PHP files are extracted to the folder location that you set up in the previous steps.

    Setting Up PHP
  5. In the folder where you extracted the PHP files, locate the php.ini-recommended file. Right-click it, and click Copy. Then right-click whitespace in the folder, and click Paste.

  6. Right-click the copied file, and then click Rename. Rename the file to php.ini.

    Setting Up PHP
  7. Close any open Windows Explorer and browser windows and return to Expression Web 2.

  8. On the Site menu, click Site Settings. In the Site Settings dialog box that opens, click the Preview tab. Ensure that the Use Microsoft Expression Development Server check box is selected, and choose either For only PHP and ASP.NET web pages or For all web pages.

  9. By default, Expression Web 2 looks for the php-cgi.exe file in the C:PHP folder or the C:Program FilesPHP folder. If you installed the PHP distribution in a different location or want to specify a different location for a specific Web site (perhaps to test against an older PHP version), click Use a PHP executable only for this website, and then click Browse. When the Select the PHP Executable to use dialog box opens, browse to your installation folder.

    Setting Up PHP
  10. Click the php-cgi file, and then click Open to open the Site Settings dialog box.

    Setting Up PHP
  11. In the Site Settings dialog box, set the path to the PHP executable, and then click OK.

  12. Return to Expression Web 2. In the Folder List, double-click the default.php file to open it for editing in Expression Web 2.

    Only one snippet of PHP code is contained in the page.

  13. To enable a visible representation of your PHP code blocks, on the View menu, point to Formatting Marks, and then click Script Blocks.

    Setting Up PHP
  14. To test your path to the PHP executable, on the toolbar, click the Preview button.

    Setting Up PHP

    Preview

    The Expression Web Development Server opens and displays the file in a browser. The PHP echo statement executes and shows HTML content where the script block tag was in the preview pane.

    Setting Up PHP

Note

Setting Up PHP

BE SURE TO leave the CH12 site open for use in the next exercise.

CLOSE your browser and return to Expression Web 2.

Tip

If the file fails to execute and you don’t see the HTML content in the previous image, look on the Preview tab in the Site Settings dialog box for the correct path to your PHP executable and Development Server options.

The first time you preview a page through the Development Server, you may see an alert dialog box stating "The php.ini file is not configured correctly. Would you like Expression Web to configure this file?"

Tip

Click Yes so that Expression Web 2 corrects the .ini file for you.

Now that you have PHP installed on your computer and configured for your site, you are ready to move on to using some of the features available in Expression Web 2.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.137.108