|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-03-22 23:46 UTC] bobwei9 at hotmail dot com
[2013-09-30 12:13 UTC] mike@php.net
-Status: Open
+Status: Duplicate
[2013-09-30 12:13 UTC] mike@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 19:00:01 2025 UTC |
Description: ------------ It would be really useful to be able to write single files that would run cleanly as *either* CGI or CLI scripts. At the moment, the closing '?>' tag will eat the trailing newline. So, similarly, I'd like to request a way for the opening '<?' tag to eat the previous literal shebang line. Test script: --------------- #!/usr/bin/php <? if (php_sapi_name()== "cgi"){ erase_previous_line() <-- hypothetical function. echo "I am CGI<br>"; }else{ echo "I am CLI\n"; } ?> Expected result: ---------------- Exactly one line should be printed: "I am CLI|CGI" Actual result: -------------- In CLI mode, this script cleanly prints: "I am CLI" but in Apache mode, the script prints the first line literally: "#!/usr/bin/php I am CGI<br>" It's relatively easy to work around this with a wrapper script, but I'd appreciate the elegance of having a single file that can operate in both modes. Thank you for your time.