Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php command line program

Status
Not open for further replies.

mysqlfrk

Programmer
Aug 3, 2011
12
I have this program-
<?php
$fname=$_SERVER['argv'][1];
$lname=$_SERVER['argv'][2];
echo "Hello!$fname \n";
echo "Hello!$lname \n";
print_r($_SERVER['argv']);
?>
Here I try to output these 2 names in 2 lines in DOS command prompt like this-
Samuel
Johnson
Unfortunately it is not showing the the 2nd output.I have saved the program as 1.php. I give this command in C prompt like these
C:\>php 1.php Samuel Johnson
Its just showing the first line
Hello! Samuel
Array
(
[0]=>1.php
[1]=>Samuel
[2]=>Johnson
)
Instead, what I want is this -
Hello!Samuel
Hello!Johnson
Array
(
[0]=>1.php
[1]=>Samuel
[2]=>Johnson
)
What can be the problem & how to rectify this?
 
Well the code has no errors. And running it on my side as is produces the expected result.

Perhaps you've done something different on your side. Is that the exact code you are using?



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi Vacunita ,Did it produce the desired result?
 
Hi

Just a guess. Try using proper DOS end of line marks :
PHP:
[b]echo[/b] [green][i]"Hello!$fname[highlight][i]\r[/i][/highlight]\n"[/i][/green][teal];[/teal]
[b]echo[/b] [green][i]"Hello!$lname[highlight][i]\r[/i][/highlight]\n"[/i][/green][teal];[/teal]
Or the generic way, use the PHP_EOL constant :
PHP:
[b]echo[/b] [green][i]"Hello!$fname"[/i][/green][highlight][teal],[/teal]PHP_EOL[/highlight][teal];[/teal]
[b]echo[/b] [green][i]"Hello!$lname"[/i][/green][highlight][teal],[/teal]PHP_EOL[/highlight][teal];[/teal]
I think your output is complete, just its displayed image is malformed. So if you redirect it into a file then view that file in a text editor, there should be everything you [tt]echo[/tt]ed out.


Feherke.
 
Hi Vacunita ,Did it produce the desired result?
Yes, both values were displayed fine.
dosouput.jpg




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top