Reply to CLI ( command-line ) PHP displaying source code in-line when program is executed

Your name:

Reply:


Posted by Double Echo on 02/12/06 16:03

Hi all,

I'm using PHP 4.4.2, and use PHP on both the command-line and the web.

I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using
Apache 2.0.55 , on my Dell laptop. Everything has been running flawlessly
without problems. Very amazing to use VMware, it has worked beautifully.

uname -a

Linux xxxxxxx 2.6.13-15.8-default #1 Tue Feb 7 11:07:24 UTC 2006 i686 i686 i386
GNU/Linux

php -v
PHP 4.4.2 (cli) (built: Feb 7 2006 20:13:29)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

php -m

[PHP Modules]
bcmath
bz2
calendar
ctype
curl
dbx
dio
domxml
exif
ftp
gd
gettext
gmp
iconv
mcrypt
mssql
mysql
ncurses
openssl
overload
pcre
posix
session
shmop
sockets
standard
sysvsem
sysvshm
tokenizer
wddx
xml
yp
zlib

[Zend Modules]


When I run the following program from the command line it prints out the
source code as well as the output from the program. I run other PHP programs
on the command-line and this doesn't happen. It's really peculiar. The
error output is below.

I copied this off of php.net, and have modified it only slightly to allow
command-line input. I was trying to find a CSV solution, which I ended up
finding elsewhere, but am curious why this program would error out the
way it does--have I misconfigured something? My php.ini is basically
unchanged, if at all. I think I might have set the path to mysql but that's
about it. When I run this program from the web it works without error.

<?php

if ( $argv[0] )
{
$file = $argv[0] ;
}
else {
$file = $_GET['file'] ;
print "<font face=arial>\n" ;
}

$row = 1;

$handle = fopen("$file", "r");

while ( ( $data = fgetcsv($handle, 1000, ",") ) !== FALSE )
{

$num = count($data);

print "$num fields in line $row:<br> \n";

$row++;

for ($c = 0; $c < $num; $c++)
{
print "$data[$c]<br> \n" ;
}

}

fclose($handle);

?>


=== COMMAND-LINE OUTPUT ===


1 fields in line 1:<br>
<?php<br>
1 fields in line 2:<br>
<br>
1 fields in line 3:<br>
if ( $argv[0] )<br>
1 fields in line 4:<br>
{<br>
1 fields in line 5:<br>
$file = $argv[0] ;<br>
1 fields in line 6:<br>
}<br>
1 fields in line 7:<br>
else {<br>
1 fields in line 8:<br>
$file = $_GET['file'] ;<br>
1 fields in line 9:<br>
print "<font face=arial>\n" ;<br>
1 fields in line 10:<br>
}<br>
1 fields in line 11:<br>
<br>
1 fields in line 12:<br>
$row = 1;<br>
1 fields in line 13:<br>
<br>
2 fields in line 14:<br>
$handle = fopen("$file"<br>
r);<br>
1 fields in line 15:<br>
<br>
3 fields in line 16:<br>
while ( ( $data = fgetcsv($handle<br>
1000<br>
,) ) !== FALSE ) <br>
1 fields in line 17:<br>
{<br>
1 fields in line 18:<br>
<br>
1 fields in line 19:<br>
$num = count($data);<br>
1 fields in line 20:<br>
<br>
1 fields in line 21:<br>
print "$num fields in line $row:<br> \n";<br>
1 fields in line 22:<br>
<br>
1 fields in line 23:<br>
$row++;<br>
1 fields in line 24:<br>
<br>
1 fields in line 25:<br>
for ($c = 0; $c < $num; $c++) <br>
1 fields in line 26:<br>
{<br>
1 fields in line 27:<br>
print "$data[$c]<br> \n" ;<br>
1 fields in line 28:<br>
}<br>
1 fields in line 29:<br>
<br>
1 fields in line 30:<br>
}<br>
1 fields in line 31:<br>
<br>
1 fields in line 32:<br>
fclose($handle);<br>
1 fields in line 33:<br>
<br>
1 fields in line 34:<br>
?> <br>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация