LIGHTENING YOUR WORKLOAD WITH INCLUDES 9. A drawback (Medical web site)

LIGHTENING YOUR WORKLOAD WITH INCLUDES 9. A drawback with this technique is that filenames consist of only one word at least they should. If you ve picked up bad habits from Windows and Mac OS X permit ting spaces in filenames, get out of them immediately. Spaces are not allowed in URLs, which is why most web design software replaces spaces with %20. You can get around this problem, though, by using an underscore. Change the name of the file you re working with so that it uses two words separated by an underscore. For example, change contact.php to contact_us.php. 10. Change the code in title.inc.php like this: The middle line uses a function called str_replace() to look for every underscore and replace it with a space. The function takes three arguments: The character you want to replace (you can also search for multiple characters) The replacement character or characters The string where you want the changes to be made You can also use str_replace() to remove character(s) by using an empty string (a pair of quotes with nothing between them) as the second argument. This replaces the string in the first argument with nothing, effectively removing it. The other change is in the final line of code. Instead of ucfirst(), it uses the related function ucwords(), which gives each word an initial cap. 11. Save title.inc.php and load into a browser the file that you renamed in step 9. Figure 4-7 shows the result with contact_us.php. Figure 4-7. With the help of str_replace(), you can even create titles that contain more than one word. 12. Change back the name of the file so that it no longer has an underscore. Reload the file into a browser. You ll see that the script in title.inc.php still works. There are no underscores to replace, so str_replace() leaves the value of $title untouched, and ucwords() converts the first letter to uppercase, even though there s only one word. 101
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Leave a Reply