Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Save bandwidth
- Add the following code at the beginning of your PHP page, and PHP will automatically compress the page to web browsers that support with feature (both Internet Explorer and Mozilla/Firefox do).
- Since HTML can easily be compressed, you can expect to cut down by at least 2/3 the bandwidth used at the expense of some extra load on the server's CPU, but the CPU load difference usually isn't even noticeable.
- <?
- @ini_set('zlib.output_compression_level', 1);
- @ob_start('ob_gzhandler');
- ?>
- Display currencies
- Sometimes we must display a number as a money amount, but we can know what's the correct way to display each possible currency. Nevermind, PHP will do that for you:
- <?
- $number = 1234.56;
- // USA (USD 1,234.56)
- setlocale(LC_MONETARY, 'en_US');
- echo money_format('%i', $number);
- // France (1 234,56 EUR)
- setlocale(LC_MONETARY, 'fr_FR');
- echo money_format('%i', $number);
- // Brazil (1.234,56 BRL)
- setlocale(LC_MONETARY, 'pt_BR');
- echo money_format('%i', $number);
- // Great Britain (GBP1,234.56)
- setlocale(LC_MONETARY, 'en_GB');
- echo money_format('%i', $number);
- // Japan (JPY 1,235)
- setlocale(LC_MONETARY, 'ja_JP');
- echo money_format('%i', $number);
- ?>
- Show the request header (For debbuging purposes)
- We occasionaly want to see very exactly what the browser sent to the webserver. Here's an easy way to do it:
- <?
- $headers = apache_request_headers();
- foreach ($headers as $header => $value) {
- echo "$header => $value <br>\n";
- }
- ?>
- This code should print something like this.
- Ignore User Abort
- Your script is doing something sensible (database updating, ...) and you absolutly don't want it to be interrupted by the user pressing the 'Stop' button of his browser?
- Just add the following code to your script:
- <?
- ignore_user_abort(true);
- ?>
- Error reporting
- Depending on whether you're programming/debbuging or installing a script on a production server, you may want error reporting more or less verbose.
- Here's how to change it:
- <?
- // Disable all error reporting
- error_reporting(0);
- // Default configuration
- error_reporting(E_ALL ^ E_NOTICE);
- // Display extra warnings about uninitialised variables, etc
- error_reporting(E_ALL);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement