ratcateme Posted February 15, 2008 Share Posted February 15, 2008 Hi i have a script with this foreach i got an "unexpected $end" i commented out all my script and traced the error to this code block foreach($ip_x as &$value){ echo $value; } i added a print_r($ip_x) and it showed me ip_x is a proper array i can comment out this block and the rest of my script works fine Scott. Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/ Share on other sites More sharing options...
Stooney Posted February 15, 2008 Share Posted February 15, 2008 try removing the '&'. That doesn't make sense to have it there. Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467480 Share on other sites More sharing options...
ratcateme Posted February 15, 2008 Author Share Posted February 15, 2008 tried that still same error Scott. Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467481 Share on other sites More sharing options...
Stooney Posted February 15, 2008 Share Posted February 15, 2008 Hmm, I don't have my server running so I can't test anything, what's some of the code before the loop? Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467482 Share on other sites More sharing options...
ratcateme Posted February 15, 2008 Author Share Posted February 15, 2008 here is the full code it is to check for a valid IP <?php $ip_error=false; $ip_x=explode('.',$ip); if(count($ip_x)==4){ print_r($ip_x); foreach($ip_x as $value){ if(!($value>0 && $value<255)){ $error=3; } echo $value; } }else{ $error=4; } ?> Scott. Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467484 Share on other sites More sharing options...
Stooney Posted February 15, 2008 Share Posted February 15, 2008 I can't help much without being able to test it which I can't until tomorrow. Maybe 'value' is a reserved word? Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467487 Share on other sites More sharing options...
ratcateme Posted February 15, 2008 Author Share Posted February 15, 2008 i changed $value to $number but no change thanks for the help Scott. Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467489 Share on other sites More sharing options...
ratcateme Posted February 15, 2008 Author Share Posted February 15, 2008 i swapped my foreach to a for loop <?php for($i=0;count($ip_x)>$i;$i++){ //foreach($ip_x as $number){ if(!($ip_x[$i]>0 && $ip_x[$i]<255)){ $error=3; } echo $ip_x[$i]; } ?> Still same problem Scott. Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467493 Share on other sites More sharing options...
PFMaBiSmAd Posted February 15, 2008 Share Posted February 15, 2008 Post the actual error message and the complete code it corresponds to. If the error is "unexpected $end", that usually means that there is a mis-match in {}. Neither of the posted pieces of code results in that error, so either the posted code is not complete or the error is different. Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467521 Share on other sites More sharing options...
ratcateme Posted February 15, 2008 Author Share Posted February 15, 2008 I have COMMENTED out all the code but this <?php $ip_x=explode('.',$ip); if(count($ip_x)==4){ print_r($ip_x); //for($i=0;count($ip_x)>$i;$i++){ foreach($ip_x as $number){ ` if(!($number>0 && $number<255)){ $error=3; } echo $number; } }else{ $error=4; } ?> and i get this error Parse error: syntax error, unexpected $end in /var/www/html/dyndns.php on line 145 i then coppied only that code into a blank php file and got this Parse error: syntax error, unexpected $end in /var/www/html/a.php on line 15 Scott. Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467983 Share on other sites More sharing options...
PFMaBiSmAd Posted February 15, 2008 Share Posted February 15, 2008 The posted code has a back-tic ` on line 7 that is causing the error. Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467987 Share on other sites More sharing options...
ratcateme Posted February 15, 2008 Author Share Posted February 15, 2008 oooor shit i didn't see that thanks lols Scott. Link to comment https://forums.phpfreaks.com/topic/91209-unknown-foreach-error/#findComment-467990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.