Jump to content

[SOLVED] Foreach Statement


jcrichard

Recommended Posts

I'm having a problem trying to use the foreach statement...

 

3: $filename = "http://www.website.com";
4: $ch = curl_init();
5: $timeout = 5;
6: curl_setopt ($ch, CURLOPT_URL, $filename);
7: curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
8: curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
9: $fcontents = curl_exec($ch);
10: curl_close($ch);
11: 
12: foreach ($fcontents as $k $v)
13:  {
14:	if (ereg("STOP ON THIS LINE",$v)) {
15:		$line=$k;
16:		break;
17:	}
18:	else {}
19:  }
20:
21: echo $fcontents[$line];

 

 

I get this error:

 

Parse error: syntax error, unexpected T_VARIABLE, expecting ')' on line 12

 

 

Anyone?

Link to comment
https://forums.phpfreaks.com/topic/48743-solved-foreach-statement/
Share on other sites

Fixed:

 

$filename = "http://www.website.com";
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $filename);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$fcontents = curl_exec($ch);
curl_close($ch);

$array = explode("\n", $fcontents);

foreach ($array as $k => $v)
{
if (ereg("STOP ON THIS LINE",$v)) {
	$line=$k;
	break;
}
else {}
}

echo $array[$line];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.