note 83241 added to function.print

From: Date: Fri, 16 May 2008 11:08:09 +0000
Subject: note 83241 added to function.print
Groups: php.notes 
Request: Send a blank email to php-notes+get-139442@lists.php.net to get a copy of this message
I wrote a println function that determines whether a \n or a <br /> should be appended to the line depending on whether it's being executed in a shell or a browser window. People have probably thought of this before but I thought I'd post it anyway - it may help a couple of people. <?php function println ($string_message) { $_SERVER['SERVER_PROTOCOL'] ? print "$string_message<br />" : print "$string_message\n"; } ?> Examples: Running in a browser: <?php println ("Hello, world!"); ?> Output: Hello, world!<br /> Running in a shell: <?php println ("Hello, world!"); ?> Output: Hello, world!\n ---- Server IP: 87.124.64.96 Probable Submitter: 86.148.87.240 ---- Manual Page -- http://www.php.net/manual/en/function.print.php Edit -- https://master.php.net/note/edit/83241 Del: integrated -- https://master.php.net/note/delete/83241/integrated Del: useless -- https://master.php.net/note/delete/83241/useless Del: bad code -- https://master.php.net/note/delete/83241/bad+code Del: spam -- https://master.php.net/note/delete/83241/spam Del: non-english -- https://master.php.net/note/delete/83241/non-english Del: in docs -- https://master.php.net/note/delete/83241/in+docs Del: other reasons-- https://master.php.net/note/delete/83241 Reject -- https://master.php.net/note/reject/83241 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139442) next »