Browsing Posts tagged PHP

Rather shameful to admit after using PHP for over a decade now, but all this time I thought it stood for Personal Home Page (PHP) Tools. Turns out sometime around PHP version 3 it became the recursive acronym, or as some would argue, the recursive initialism PHP: Hypertext Preprocessor. - http://php.net/manual/en/history.php.php - never knew!

The closing ?> tag MUST be omitted from files containing only PHP.

- (PSR2.2)

The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include or require, so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.

- http://php.net/basic-syntax.instruction-separation

If a file is pure PHP code, it is preferable to omit the PHP closing tag at the end of the file.

- http://php.net/manual/en/language.basic-syntax.phptags.php


Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /homepages/24/d152177141/htdocs/techblog.tonycollings.com/wp-content/plugins/code-highlighter/geshi.php on line 2147

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /homepages/24/d152177141/htdocs/techblog.tonycollings.com/wp-content/plugins/code-highlighter/geshi.php on line 2147

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /homepages/24/d152177141/htdocs/techblog.tonycollings.com/wp-content/plugins/code-highlighter/geshi.php on line 2147

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /homepages/24/d152177141/htdocs/techblog.tonycollings.com/wp-content/plugins/code-highlighter/geshi.php on line 2147

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /homepages/24/d152177141/htdocs/techblog.tonycollings.com/wp-content/plugins/code-highlighter/geshi.php on line 2147

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /homepages/24/d152177141/htdocs/techblog.tonycollings.com/wp-content/plugins/code-highlighter/geshi.php on line 2147

Huh! This is an interesting dilemma I came across today. Take some fairly standard PHP export script:

  1. span style="color: #ff0000;">"Content-type: application/vnd.ms-excel""Content-Disposition: attachment; filename=some-filename.xls");
  2.  

... set some headers and print($sMyCSVFile);. Well NOT so much with Internet Explorer. Works perfectly with everything else.

Turns out that there is a known issue opening documents over SSL with Internet Explorer. (MSDN Article: 316431) and it's all to-do with caching! If EITHER of the following headers exist then the script will fail:

  1.  

The answer; it turns out, is relatively easy. Simply set :

  1.  

.. Voila! There are also some nice examples of forcing file-download on php.net (http://us3.php.net/manual/en/function.readfile.php)


Further Reading: