Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Output result from PHP regex search.

Options
  • 28-09-2009 6:20pm
    #1
    Registered Users Posts: 2,234 ✭✭✭


    Hey,

    It's my first attempt at trying to isolate a piece of text from a html string that was scraped with PHPs CURL!

    I have the html and am trying to search for the text in red:
    <TD><B>Total Downloads to date this month: </B></TD><TD ALIGN=RIGHT>&nbsp;[COLOR="Red"]21892[/COLOR] MB</TD>
    

    I took this expression from a tutorial site:
    $html = preg_match("/Total Downloads to date this month: <\/B><\/TD><TD ALIGN=RIGHT>&nbsp;(.*) MB<\/TD>/", $html, $matches);
    

    The only problem is that I can't print anything from the $matches array.
    $matches[0] is undefined etc etc..

    Any ideas on this? I know I should probably learn about regular expression but they seem to scary tbh!

    Thanks.


Comments

  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    If your PHP version is 5.2.0 or newer you could use the filter_var function.
    http://www.w3schools.com/PHP/filter_validate_int.asp
    [PHP]$extracted_number = filter_var( $html, FILTER_VALIDATE_INT);[/PHP]
    Or simplify your regular expression to only look for numbers:
    [PHP]$whether_found = preg_match( "/(\d+)/", $html, $matches );
    if ($whether_found) print_r($matches); // This will display the matches, if any.[/PHP]


Advertisement