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 ?

0

2 Answers 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);.

Sign up to request clarification or add additional context in comments.

Comments

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

4 Comments

But, is my format is incorrect or any symbol i have just ignored ?
your making a sting from an array, incorrectly, then turning it back in to an array.
Your solution is creative. thanks. But may be using arry will be make it easier ?
i use an array in both examples, the first is identical to the answer by jan267. if you are not reusing $a, my 2nd option is more efficient (less memory use)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.