Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid showing "#!/usr/bin/php" on PHP?

I want PHP scripts to run both on command line and website (I use Apache and Nginx) so I put #!/usr/bin/php in the first line of my scripts but that appears on the website...

like image 450
brainsqueezer Avatar asked Nov 05 '10 11:11

brainsqueezer


People also ask

How do you avoid showing off?

Choose words carefully Show-offs continue to seek attention until they get it, so ignoring their behaviour is unlikely to make it stop. Praise them, but choose your words carefully. 'Saying, “You're so good at this” reinforces the idea that they're special and stand out,' says psychologist Jean Twenge.

Why do I love showing off?

Insecurity. It's the most common reason behind showiness. A person shows off only when they need to. Only when they think that others don't consider them important will they try to prove that they're important.

Why is showing off important?

The content which you show off is of great importance. Everything cannot be of great importance in ones life until it is very expensive, everyone will agree with this point. Show off is something that you wish to show everyone about the matter or object or anything that makes you feel unique.


2 Answers

I solved the problem using output buffering. My script now looks like this:

#!/usr/bin/php
<?php
@ob_end_clean();
...

Note: There is no ?> at the end of the file. This is actually a good practice when writing PHP scripts. This prevents any garbage text to be accidentally printed.

Note: The PHP documentation for ob_end_clean() says that:

The output buffer must be started by ob_start() with PHP_OUTPUT_HANDLER_CLEANABLE and PHP_OUTPUT_HANDLER_REMOVABLE flags. Otherwise ob_end_clean() will not work.

It seems that this is done automatically when PHP runs from command line.

like image 62
Viliam Simko Avatar answered Nov 15 '22 20:11

Viliam Simko


There is no need to have #!/usr/bin/php in your code, just run CLI script using php, for example php /path/to/file.php or /usr/bin/php /path/to/file.php.

like image 25
David Kuridža Avatar answered Nov 15 '22 18:11

David Kuridža