Creating a PHP Page

Although just about any HTM or HTML file can be renamed to have a .php extension, you may run into trouble with Byte Order Marks (BOMs). A BOM is a Unicode character used to denote the beginning of a string of Unicode characters and to serve as a marker that indicates the text is encoded in UTF-8, UTF-16, or UTF-32. In most cases, it will never be visible in a browser but it can cause problems in PHP files.

To avoid a BOM, it’s best to create a new PHP file directly from the New Document menu in Expression Web 2. However, converting an existing HTM/HTML file to PHP is a solution you may need when working within an existing file that you want to run PHP scripting on. You’ll learn how to do this in the next topic.

In this exercise, you will create a PHP page in Expression Web 2.

Note

Creating a PHP Page

USE the CH12 sample site you modified in the previous exercise.

OPEN the CH12 site if it isn’t already open.

Troubleshooting

In order to follow the steps in this exercise, you will need to have completed the preceding exercise—specifically, installing and configuring PHP on your computer and ensuring that the Expression Web 2 Development Server is set to the correct path leading to the PHP executable.

  1. In the Folder List, double-click the default.php file to open it for editing. Right-click the script block in the Design pane, and then click Copy.

  2. Click the New Document arrow, and then click PHP.

    Troubleshooting

    New Document

    Troubleshooting

    Expression Web 2 creates a new PHP file named Untitled_1.php.

  3. Right-click in the Design pane of your new page, and then click Paste to paste the code block you copied in step 1.

  4. Save your page to the root folder of your site as MyPHP.php, and preview it in a browser to ensure that the PHP code executes.

    Troubleshooting
  5. Close your browser and return to Expression Web 2. On the Format menu, point to Dynamic Web Template, and then click Attach Dynamic Web Template.

    The Attach Dynamic Web Template dialog box opens.

  6. In the Attach Dynamic Web Template dialog box, click the default.dwt file, and then click Open.

    The Match Editable Regions dialog box opens.

  7. In the Match Editable Regions dialog box, keep the default selection, and click OK. Then click Close in the updated pages dialog box that opens.

    You now have a PHP page with an Expression Web Dynamic Web Template attached to it.

    Troubleshooting

    Depending on your workflow and the type of Web site you’re working on, the ability to attach a Dynamic Web Template to a PHP file can be very useful.

  8. Save your page and preview it in a browser to ensure that it works and displays the content contained in the PHP echo statement.

    Troubleshooting
  9. Close your browser and return to Expression Web 2.

Note

Troubleshooting

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

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

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