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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Output result from PHP regex search.

  • 28-09-2009 5:20pm
    #1
    Registered Users, Registered Users 2 Posts: 2,237 ✭✭✭


    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,602 ✭✭✭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