0

I want to grab specific array elements from CURl output. So, I am trying to make a script. Here is:

<?php
$url = "example.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$buffer = curl_exec($ch);
$explode=explode("name",$buffer);
$a=($explode[89],$explode[18],$explode[58],$explode[36],$explode[49],$explode[58],$explode[68],$explode[78],$explode[88],$explode[98],$explode[108],$explode[118],$explode[158],$explode[138],$explode[148],$explode[158],$explode[168],$explode[178],$explode[188],$explode[198],$explode[508],$explode[518],$explode[558],$explode[538],$explode[548]);
$p=explode(",",$a);
foreach($p as $b){
     $c=explode("name-finish",$b);
     echo ($c[0]);
}   
?>

But it is showing

Parse error: syntax error, unexpected ',' on line 23

( this is line of $a )

What is my error here ?

4

2 回答 2

2

Try with:

$a=array($explode[89],$explode[18],$explode[58],$explode[36],$explode[49],$explode[58],$explode[68],$explode[78],$explode[88],$explode[98],$explode[108],$explode[118],$explode[158],$explode[138],$explode[148],$explode[158],$explode[168],$explode[178],$explode[188],$explode[198],$explode[508],$explode[518],$explode[558],$explode[538],$explode[548]);

and then remove the line: $p=explode(",",$a);.

于 2012-11-25T19:06:08.660 回答
1

drop the $a=.. and $p.. lines and replace with this:

$explode=explode("name",$buffer);
$a[]=$explode[89];
$a[]=$explode[58];

....

then

foreach($a as $b){...

OR

foreach (array($explode[89],$explode[58] ...) as $b){...

better if you are not going to use the array again

于 2012-11-25T19:04:30.533 回答