[solved]for 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
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

[solved]for loop

Post by vigge89 »

i've got the following code in my script;

Code: Select all

<?php
	for ($i = 1; $i <= 4; $i++) {
		if (empty ($_POST['entry_{$i}']) || $_POST['entry_{$i}'] == 'http://') { $_POST['entry_{$i}'] = "empty"; }; //If entry is empty
		$_POST['entry_{$i}'] = addslashes($_POST['entry_{$i}']); //Add slashes for security
	}
?>
but, of course i don't work. the $_POST['entry_{$i}'] apparently doesn't work very well. but now on to the question;
Is it possible to do this somehow? Becuase i don't really want to have 10 extra lines doing it when i just could use a loop....
Last edited by vigge89 on Sun Jan 18, 2004 2:30 pm, edited 1 time in total.
User avatar
Fredix
Forum Contributor
Posts: 101
Joined: Fri Jul 18, 2003 2:16 pm
Location: Wehr (Eifel) Germany
Contact:

Post by Fredix »

I do believe it is because you use single quotes instead of normal double quotes. Try sth. like this:

Code: Select all

<?php
$_POST["entry_{$i}"] = "blabla";
?>
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

well, what can i say, it tried that at first, but i don't think i used them in all $_POST['entry_{$i}'], but now it seems to work, thanks! ;)
Post Reply