PHP Includes and Design View Integration
Many PHP developers use Dreamweaver as their primary development tool. After the release of Expression Web 1 (EW1), various articles appeared comparing the strengths and weaknesses of Dreamweaver and Expression Web from the point of view of a PHP developer. One deficiency of EW1 frequently pointed out in comparisons of this type was the inability of EW1 to display PHP includes in design view. Part of my preparation for this article included the creation of a relatively simple website for a friend using PHP. I started out by creating a logo and a menu structure. Since I wanted every page in this website to include both of these items, I decided to use the technique of a PHP include. So I extracted the common elements from my home page design and saved it in a separate PHP file. Incorporating these common elements in each page simply required adding the following line of code: <?php include('PSHeader.php'); ?>. Even though these common elements are actually contained in a separate file, EW2's design view displays a composite view which is indistinguishable from that which would be generated if all the content were actually contained in a single file. Figure 2 shows what elements are used in the include and what is unique to the page.
 | | | Figure 2. Displaying a common header using a PHP include is easy with Expression Web 2. |
This linked screencast illustrates how simple it is to use PHP includes.
Byte Order Marks (Problem Solved)
The initial release of Expression Web (January 2006) was targeted at ASP.NET developers and apparently the EW development team was unable to also manage to include optimizing the application for PHP developers in the first edition. Not surprisingly therefore, those PHP developers who tried to use Expression Web for their projects encountered a number of problems. For example, some developers discovered that EW 1 added a Byte Order Mark (BOM) to all of the HTML, PHP and CSS files which it creates using UTF-8 encoding. (The purpose of the BOM is to specify whether the least significant byte is placed first—as required by Intel and MIPS processors—or last—as required by Motorola processors.) The practical effect of these BOMs in PHP files was to frequently prevent PHP includes from working properly when the referencing page was delivered from a web server.
The Byte Order Mark problem has now been eliminated in EW2 by the simple step of giving the user complete control over whether or not to include a BOM in any new document. The applicable settings allow this decision to be made on a file type by file type basis Figure 3). Moreover, Microsoft set BOMs to OFF as the default for .PHP files. (The ON setting remains the default for all other common web project file types such as .HTM, .HTML, .CSS and .XML.)
 | | | Figure 3. You can now set Byte Order Marks on each individual file type or document in Expression Web 2. |
EW 2 even allows the BOM setting to be overridden on a document by document basis as the developer sees fit. You can access a document's properties by right clicking on the document in the editor window and selecting Encoding. HTML encoding settings can be found on the Language tab. As shown below, including a BOM is only allowed when UTF-8 encoding has been selected (Figure 4).
 | | | Figure 4. Byte order marks can only be set on UTF-8 documents. |
This linked screencast illustrates both how BOMs in a PHP document can cause problems for PHP includes and also shows how to access the EW settings to control the inclusion of BOMs.
|