...

View Full Version : Scraping data with regex



Jacobb123
02-29-2008, 05:59 AM
I need to match what is in the double quotes after value in the following lines. Of course it will be different depending on the values of the page.

<input type="hidden" name="timestamp" value="1204248942133"/>

<input type="hidden" name="js" value="aLGqVpq6QtJb">
<input type="hidden" name="userid" value="194172226">

I have the following code but when I try and print the data it just says array. not sure where i have gone wrong


preg_match_all('/<input[^>]+value\s*=\s*"([^"]*)"[^>]*>/',$page,$matches);

echo $matches[1];

Inigoesdr
02-29-2008, 06:02 PM
print_r($matches);
Will show you your matches in the second key of the array:

Array
(
[0] => Array
(
[0] => <input type="hidden" name="timestamp" value="1204248942133"/>
[1] => <input type="hidden" name="js" value="aLGqVpq6QtJb">
[2] => <input type="hidden" name="userid" value="194172226">
)

[1] => Array
(
[0] => 1204248942133
[1] => aLGqVpq6QtJb
[2] => 194172226
)

)
So, you would access them like this:

echo $matches[1][0];
echo $matches[1][1];
echo $matches[1][2]; // etc.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum