ADFB
asked on
PHP preg_match_all problem
What's wrong with this script...
I'm trying to extract URLs:
I get this error:
Parse error: syntax error, unexpected ',', expecting ']' in ... on line 10
It's the same when I don't escape the = sign either.
I'm trying to extract URLs:
<?php
$on='0';
$url='http://www.gutenberg.org/robot/harvest?offset='.$on.'&filetypes[]=txt&langs[]=en';
$output=file_get_contents($url);
preg_match_all('/f=\"(.*)\.zip/', $output, $matches);
$num=count($matches); echo $num.'<br>';
for($run=0; $run<$num; $run++)
echo $matches[$run,0].' > '.$matches[$run,1].' > '.$matches[$run,2].'<br>';
?>
I get this error:
Parse error: syntax error, unexpected ',', expecting ']' in ... on line 10
It's the same when I don't escape the = sign either.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I didn't know of that notation " $matches[$run,0]"Ooops! That was my problem, from an old programming language I used to use.
And so?
Rik's script will only output the FIRST line of matches.
Was that your intention?
Rik's script will only output the FIRST line of matches.
Was that your intention?
$matches[$run][0].
Try to modify your code as follows:
...
for($run=0; $run<$num; $run++)
echo $matches[$run][0].' > '.$matches[$run][1].' > '.$matches[$run][2].'<br>'
...
HTH Bye!