Link to home
Start Free TrialLog in
Avatar of ADFB
ADFB

asked on

PHP preg_match_all problem

What's wrong with this script...

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>';

?>

Open in new window


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.
Avatar of ienaxxx
ienaxxx
Flag of Italy image

I didn't know of that notation " $matches[$run,0]" to recall
$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!
ASKER CERTIFIED SOLUTION
Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ADFB
ADFB

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?