473,856 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CLI ( command-line ) PHP displaying source code in-line when programis executed

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"<b r>
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);<b r>
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>


Feb 12 '06 #1
3 3042
Echo Echo,

At the beginning output $file. For some reason the file is reading
itself as input. If you are using:

php myprog.php infile.csv

....on the command line then I think you should be trying to get
"infile.csv " (or whatever) using $argv[1] not $argv[0]. Otherwise you
are passing the files own source to itself and the line

print "$data[$c]<br> \n" ;

Is causing the source to print.

-Robert

Feb 12 '06 #2
You're right!!

I'm smacking myself--too much coding!!

I changed it on my other progs but forgot to on this one.

Thanks!
rlee0001 wrote:
Echo Echo,

At the beginning output $file. For some reason the file is reading
itself as input. If you are using:

php myprog.php infile.csv

...on the command line then I think you should be trying to get
"infile.csv " (or whatever) using $argv[1] not $argv[0]. Otherwise you
are passing the files own source to itself and the line

print "$data[$c]<br> \n" ;

Is causing the source to print.

-Robert


Feb 12 '06 #3
On 2006-02-12, Double Echo <do********@you r.com> wrote:
Hi all,

I'm using PHP 4.4.2, and use PHP on both the command-line and the web. 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.
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>
.....

<?php

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


argv[0] is the name of the PHP script.

your program is reading itself and printing itself out.
use argv[1];

--

Bye.
Jasen
Feb 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1333
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland newsgroups I learned that there is a function in stdlib.h called system. int system(const char *command); First question, is the system command ANSI compliant. Because I include <cstdlib> and write std::system(command.c_str()); it looks like an...
6
28222
by: Toralf Kirsten | last post by:
Hi, we are using db2 8.1 on Linux. I'd like to close all open connection at a defined time point. Therfore I wrote a sql script including the command disconnect all or release all
0
1119
by: Nadav | last post by:
Hi, I am writing an AddIn that adds a new EnvDTE.Command, upon setting a key for the command ( Command.Bindings = "Global::f12" ) an exception is being generated... Why can't I set a Key for the command? How could I resolve this problem???? ThanX Nadav.
1
3849
by: Mike | last post by:
Hello, How do I pass variables to a command text.(C#)Because of the quotes,it seems that the values are not passed. Thanks, Mike
3
2234
by: Anony Mous | last post by:
Hi, I've run into a problem. I've had postgres V8 beta on my WinXP Pro machine for some time now, and it's been running great. Now, for some reason, I cannot issue any queries to the database via psql. See snippit below... ------------ C:\Program Files\PostgreSQL\8.0-beta1\bin>createdb -U postgres test CREATE DATABASE
3
4859
by: Michael Roebuck | last post by:
Hi all I'm very new to VB - I am trying to run a DOS command from within a VB2005 asp.net web site using a command button? The DOS command will take the form of the command followed by several switches! Any ideas examples gratefully accepted.
5
1583
by: Jonay Aloat | last post by:
I know that I can use the news group to post questions. But last time, one of my friend show me that you can do the same thing using a unix command. I don't remember the command, but I know it is not "trn", or "archie". Can someone tell me what is the command? Thanks in advance; -Keal
1
1367
by: Sub-Lt | last post by:
Hello! We are upgrading one of our apps from VB6 to VS2005(VB). Barcode printing is part of the app. What we used to do is send the printer command directly to the printer. Printer.print {long printer command} would work. Since that doesn't exist anymore, how do we go about sending this printer command to the barcode printer? The drawstring meathod prints the command as an actual string on the barcode. I think it sees it as a graphic...
3
7019
by: Vlad | last post by:
I am trying to run the dos command "rename C:\Temp\MyTest1.txt MyTest2.txt" from VB.net - to use the shell command I have found I have to use a bat file otherwise I get an "The system cannot find the file specified" error. I am trying to use Dim MyProcess As New ProcessStartInfo MyProcess.FileName = "ren" MyProcess.Arguments = "C:\Temp\MyTest1.txt MyTest2.txt"
2
2134
by: black_13 | last post by:
how do i exec a command (such as xcopy) from with win32 python and wait on that command to come to completion? and also cleanly terminate the command shell? thanks black_13
0
9916
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9762
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11057
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10696
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10384
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7932
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5761
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4174
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.