Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. Save bandwidth
  2.  
  3. 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).
  4. 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.
  5. <?
  6. @ini_set('zlib.output_compression_level', 1);
  7. @ob_start('ob_gzhandler');
  8. ?>
  9.  
  10. Display currencies
  11.  
  12. 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:
  13. <?
  14. $number = 1234.56;
  15.  
  16. // USA (USD 1,234.56)
  17. setlocale(LC_MONETARY, 'en_US');
  18. echo money_format('%i', $number);
  19.  
  20. // France (1 234,56 EUR)
  21. setlocale(LC_MONETARY, 'fr_FR');
  22. echo money_format('%i', $number);
  23.  
  24. // Brazil (1.234,56 BRL)
  25. setlocale(LC_MONETARY, 'pt_BR');
  26. echo money_format('%i', $number);
  27.  
  28. // Great Britain (GBP1,234.56)
  29. setlocale(LC_MONETARY, 'en_GB');
  30. echo money_format('%i', $number);
  31.  
  32. // Japan (JPY 1,235)
  33. setlocale(LC_MONETARY, 'ja_JP');
  34. echo money_format('%i', $number);
  35. ?>
  36. Show the request header (For debbuging purposes)
  37.  
  38. We occasionaly want to see very exactly what the browser sent to the webserver. Here's an easy way to do it:
  39. <?
  40. $headers = apache_request_headers();
  41. foreach ($headers as $header => $value) {
  42. echo "$header => $value <br>\n";
  43. }
  44. ?>
  45. This code should print something like this.
  46.  
  47. Ignore User Abort
  48.  
  49. 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?
  50. Just add the following code to your script:
  51. <?
  52. ignore_user_abort(true);
  53. ?>
  54. Error reporting
  55.  
  56. Depending on whether you're programming/debbuging or installing a script on a production server, you may want error reporting more or less verbose.
  57. Here's how to change it:
  58. <?
  59. // Disable all error reporting
  60. error_reporting(0);
  61.  
  62. // Default configuration
  63. error_reporting(E_ALL ^ E_NOTICE);
  64.  
  65. // Display extra warnings about uninitialised variables, etc
  66. error_reporting(E_ALL);
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement