exec loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zizzu
Forum Newbie
Posts: 1
Joined: Mon Mar 21, 2011 9:45 am

exec loop

Post by zizzu »

Hello i am trying to execute a linux program for every line of a textarea

Code: Select all

	$text = $_POST['links'];
	
	$text = htmlspecialchars($_POST['links']);
	$text = nl2br($text);
	
	foreach(explode("\n",$text) as $row)
	{
		$result = NULL;
		$command = 'the command';
		exec($command,&$result);
		echo $result[0]."<br>";
	}
but this always print the result for last line of text area :(
for example is there are 3 lines it print 2 blanks and 1 result...
whats wrong??
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: exec loop

Post by Jonah Bron »

For starters, remove the htmlspecialchars and nl2br. Those are not necessary in this case. If you use htmlspecialchars, do it on the result. Do you realize that what you're doing is extremely dangerous?
Post Reply