PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY If (Web hosting support)
PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY If you ve been using CSS for a while, you ll know that putting anything above the DOCTYPE declaration forces browsers into quirks mode. However, this doesn t apply to PHP code, as long as it doesn t send any output to the browser. The code in title.inc.php only assigns a value to $title, so the DOCTYPE declara- tion remains the first thing that the browser sees, and any CSS is displayed in standards-compliant mode. 7. Save both pages and load the web page into a browser. Figure 4-6 shows how the change is reflected in contact.php. Figure 4-6. Once you extract the filename, it s possible to create the page title dynamically. 8. Not bad, but what if you prefer an initial capital letter for the part of the title derived from the filename? Nothing could be simpler. PHP has a neat little function called ucfirst(), which does exactly that (the name is easy to remember once you realize that uc stands for uppercase ). Add another line to the code in step 4 like this: When confronted by something like this, some people start breaking out into a sweat, convinced that programming is a black art that is the work of the devil or at least of a warped mind. Actually, it s quite simple: the first line of code after the PHP tag gets the filename, strips the .php off the end, and stores it as $title. The next line takes the value of $title, passes it to ucfirst() to capitalize the first letter, and stores the result back in $title. So, if the filename is contact.php, $title starts out as contact, but by the end of the following line it has become Contact. You can shorten the code by combining both lines into one like this: $title = ucfirst(basename($_SERVER[’SCRIPT_NAME’], ‘.php’)); When you nest functions like this, PHP processes the innermost one first and passes the result to the outer function. It makes your code shorter, but it s not so easy to read.
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.