tailieunhanh - Giải pháp thiết kế web động với PHP - p 11
LIGHTENING YOUR WORKLOAD WITH INCLUDES 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 filename of to . 8. Amend the code in like this: | LIGHTENING YOUR WORKLOAD WITH INCLUDES 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 filename of to . 8. Amend the code in like this php title basename _SERVER SCRIPT_FILENAME .php title str_replace _ title title ucwords title 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 s you want to replace the replacement character s and the string you to change. 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. Instead of ucfirst the final line of code uses the related function ucwords which gives each word an initial cap. 9. Save and load the renamed into a browser. Figure 4-7 shows the result. Figure 4-7. The underscore has been removed and both words have been given initial caps. 10. Change the name of the file back to and reload the file into a browser. The script in 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. 11. The home page of the Japan Journey site is called . As Figure 4-8 shows applying the current solution to this page doesn t seem quite right. 81 CHAPTER 4 Download from Wow eBook Figure 4-8. Generating the page title from produces an unsatisfactory result. There are two solutions either don t apply this technique to such pages or use a conditional statement an if statement to handle special cases. For instance to display Home instead of Index amend the .
đang nạp các trang xem trước