LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-10-2010, 11:43 AM   #1
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Rep: Reputation: 18
PHP Outputs Metadata or File Information at the Top of its Output


Hi,


Consider this PHP Script or just skip to the Output:

Code

Code:
-bash-2.05b# cat myDate.php
#!/usr/bin/php -q
<?php
        echo "\nHello world of PHP CLI!\n";
        $tomorrow       =       mktime(0,0,0,date("m"),date("d") + 1,date("Y")) . "\n";
        echo "\nTomorrow it will be: " . date("d-M-Y",$tomorrow) . "\n";
?>
-bash-2.05b#

Output:

Code:
-bash-2.05b# php myDate.php
Content-type: text/html
X-Powered-By: PHP/4.3.10


Hello world of PHP CLI!

Tomorrow it will be: 11-Sep-2010
-bash-2.05b#

How can we suppress / remove the lines (in red color above) given below from being output?

PHP Code:
Content-typetext/html
X
-Powered-ByPHP/4.3.10 

Okay, on a UNIX Box I have this workaround:

Code:
-bash-2.05b# php myDate.php | tail -n +3


Hello world of PHP CLI!

Tomorrow it will be: 11-Sep-2010
-bash-2.05b#
But is there any appropriate option to achieve the same result?

Last edited by Hi_This_is_Dev; 09-10-2010 at 12:07 PM.
 
Old 09-10-2010, 01:23 PM   #2
suprstar
Member
 
Registered: Aug 2010
Location: Atlanta
Distribution: ubuntu, debian
Posts: 142
Blog Entries: 2

Rep: Reputation: 21
Your php interpreter isn't picking up the -q for some reason. The -q should do it. The -q means to run in 'quiet' mode, to supress the http header output. This is the original file, and my output when I run it:

Code:
[root@te1 ~]# cat test.php
#!/usr/bin/php -q
<?php
        echo "\nHello world of PHP CLI!\n";
        $tomorrow       =       mktime(0,0,0,date("m"),date("d") + 1,date("Y")) . "\n";
        echo "\nTomorrow it will be: " . date("d-M-Y",$tomorrow) . "\n";
?>
[root@te1 ~]# ./test.php

Hello world of PHP CLI!

Tomorrow it will be: 11-Sep-2010
[root@te1 ~]#
then when I edit the file and remove -q:

Code:
[root@te1 ~]# cat test.php
#!/usr/bin/php
<?php
        echo "\nHello world of PHP CLI!\n";
        $tomorrow       =       mktime(0,0,0,date("m"),date("d") + 1,date("Y")) . "\n";
        echo "\nTomorrow it will be: " . date("d-M-Y",$tomorrow) . "\n";
?>
[root@te1 ~]# ./test.php
Content-type: text/html
X-Powered-By: PHP/4.3.11


Hello world of PHP CLI!

Tomorrow it will be: 11-Sep-2010
[root@te1 ~]#
If I call the 'php -q' directly, the headers are suppressed even if the interpreter in the file doesn't have the -q flag:

Code:
[root@te1 ~]# cat test.php
#!/usr/bin/php
<?php
        echo "\nHello world of PHP CLI!\n";
        $tomorrow       =       mktime(0,0,0,date("m"),date("d") + 1,date("Y")) . "\n";
        echo "\nTomorrow it will be: " . date("d-M-Y",$tomorrow) . "\n";
?>
[root@te1 ~]# php -q test.php

Hello world of PHP CLI!

Tomorrow it will be: 11-Sep-2010
[root@te1 ~]#
Is your php aliased to something, or maybe a symlink, or ?? That's really weird..
 
Old 09-10-2010, 01:34 PM   #3
suprstar
Member
 
Registered: Aug 2010
Location: Atlanta
Distribution: ubuntu, debian
Posts: 142
Blog Entries: 2

Rep: Reputation: 21
OH DUH! You're calling

php myDate.php

you need to call

php -q myDate.php

or simply

./myDate.php

I didn't notice you were calling php and not the script. Since you called php from the command line, the flags on the interpreter lines in the file are ignored. The 3 examples I showed above illustrate this. Since you're calling the interpreter from the command line, the first line of the file is a comment, not the path to the interpreter..

Last edited by suprstar; 09-10-2010 at 01:35 PM.
 
1 members found this post helpful.
Old 09-10-2010, 01:55 PM   #4
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by suprstar View Post
OH DUH! You're calling

php myDate.php

you need to call

php -q myDate.php

or simply

./myDate.php

I didn't notice you were calling php and not the script. Since you called php from the command line, the flags on the interpreter lines in the file are ignored. The 3 examples I showed above illustrate this. Since you're calling the interpreter from the command line, the first line of the file is a comment, not the path to the interpreter..


Okay, I found the solution. But thanks for the -q part which I learned from you.

PHP Code:
 -q               Quiet-mode.  Suppress HTTP Header output

-f is also producing the same result.

Code:
-bash-2.05b# php -f myDate.php

Hello world of PHP CLI!

Tomorrow it will be: 11-Sep-2010
-bash-2.05b#
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to extract metadata information using exiftool for specific model of camera??? confused.com Linux - Newbie 1 02-03-2010 07:58 AM
How do I output information from a PHP page to an HTML page? SentralOrigin Programming 3 01-10-2009 02:54 AM
How to extract metadata information using exiftool for specific model of camera??? confused.com Programming 1 10-17-2008 09:01 PM
metadata information Prasun1 Linux - General 7 06-28-2005 12:32 AM
redirecting output to multiple outputs granny Linux - General 6 02-13-2004 08:18 AM


All times are GMT -5. The time now is 08:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration