Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post

    Scraping data with regex

    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

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

    echo 
    $matches[1]; 

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    PHP Code:
    print_r($matches); 
    Will show you your matches in the second key of the array:
    Code:
    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:
    PHP Code:
    echo $matches[1][0];
    echo 
    $matches[1][1];
    echo 
    $matches[1][2]; // etc. 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •