Replacing Strings in Source Code

In this task, you will replace a handful of simple tags. For example, you will replace all instances of <br> with <br />. These changes are straightforward, because there are no attributes or variations to throw off the search. (In contrast, tags such as <img src="images/imagename.gif"> are going to be a little more work, thanks to their attributes; we'll wrestle with these harder ones shortly.)

  1. Choose Edit > Find and Replace to open the dialog once again.

    This time, rather than pasting information in, you can just type directly in the text areas.

  2. Type <br> in the upper text area, and type <br /> in the lower one (don't forget the space between the r and the / character). Be sure that you have completely removed the text that was in these windows from before.

    The Find In drop-down should still say Entire Current Local Site, which is what you want, as is Source Code in the Search For drop-down.


  3. Click Replace All.

    Once again, you see the warning, and the Results panel displays the changes. In this case, there were quite a few changes made throughout the site.

  4. Repeat steps 2 and 3 to replace <hr> with <hr />.

    Find and Replace makes quick work of what otherwise would be a very tedious task.

  5. Repeat steps 2 and 3 to replace <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> with <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />.


    To avoid typing this string, you can copy it from line 6 on any of the pages.

    The original Newland site was created in Dreamweaver, and it automatically added the <meta> tag you are replacing here. Generally, developers use the <meta> tag to convey information about a document. You'll often see <meta> tags with descriptions and keyword lists. Since these obviously vary, they can be a challenge to update through Find and Replace. But in this particular case, that's not a problem. On each page, Dreamweaver added only one <meta> tag, each time with the same contents. You can therefore be confident that you fixed them all.

  6. Repeat steps 2 and 3 to replace <map name="navbarMap"> with <map name="navbarMap" id="navbarMap">.

    Certain Web page objects have identifying attributes, which, among other things, enable the object to be accessed and even manipulated by scripts. In previous versions of HTML, you'd use the name attribute to give an object a unique identifier. In XHTML, the proper identifier has changed from name to id. Unfortunately, a lot of older browsers don't yet recognize id. And you can assume that newer browsers eventually won't recognize name. The way to work around this problem is to include both name and id attributes set to the same values, so that all browsers can recognize them.


  7. Save index.htm.