Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Output result from PHP regex search.

  • 28-09-2009 06:20PM
    #1
    Registered Users, Registered Users 2 Posts: 2,238 ✭✭✭


    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, Registered Users 2 Posts: 6,653 ✭✭✭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