13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

530 Chapter 24 Other Useful Features<br />

The ini_get() function simply checks the value of a particular configuration directive.The<br />

directive name should be passed to it as a string. Here, it just checks that the<br />

value really did change.<br />

Not all INI options can be set this way. Each option has a level at which it can be set.<br />

The possible levels are<br />

n <strong>PHP</strong>_INI_USER—You can change these values in your scripts with ini_set().<br />

n <strong>PHP</strong>_INI_PERDIR—You can change these values in php.ini or in .htaccess or<br />

httpd.conf files if using Apache.The fact that you can change them in .htaccess<br />

files means that you can change these values on a per-directory basis—hence the<br />

name.<br />

n <strong>PHP</strong>_INI_SYSTEM—You can change these values in the php.ini or httpd.conf<br />

files.<br />

n <strong>PHP</strong>_INI_ALL—You can change these values in any of the preceding ways—that is,<br />

in a script, in an .htaccess file, or in your httpd.conf or php.ini files.<br />

The full set of ini options <strong>and</strong> the levels at which they can be set is in the <strong>PHP</strong> manual<br />

at http://www.php.net/ini_set.<br />

Highlighting Source Code<br />

<strong>PHP</strong> comes with a built-in syntax highlighter, similar to many IDEs. In particular, it is<br />

useful for sharing code with others or presenting it for discussion on a web page.<br />

The functions show_source() <strong>and</strong> highlight_file() are the same. (The<br />

show_source() function is actually an alias for highlight_file().) Both of these functions<br />

accept a filename as the parameter. (This file should be a <strong>PHP</strong> file; otherwise, you<br />

won’t get a very meaningful result.) Consider this example:<br />

show_source(‘list_functions.php’);<br />

The file is echoed to the browser with the text highlighted in various colors depending<br />

on whether it is a string, a comment, a keyword, or HTML.The output is printed on a<br />

background color. Content that doesn’t fit into any of these categories is printed in a<br />

default color.<br />

The highlight_string() function works similarly, but it takes a string as parameter<br />

<strong>and</strong> prints it to the browser in a syntax-highlighted format.<br />

You can set the colors for syntax highlighting in your php.ini file.The section you<br />

want to change looks like this:<br />

; Colors for Syntax Highlighting mode<br />

highlight.string = #DD0000<br />

highlight.comment = #FF9900<br />

highlight.keyword = #007700

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!