#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    75
    Rep Power
    11

    2nd pair of eyes


    For what ever reason this is not working as far as i can tell it should be. Im just Trying to get everything between the specific <td class=\"back_build\"> tags. I told it to ignore the spaing with the \s* but it returns no results. Need a second pair of eyes to see what I may be missing.

    Code:
    <?
    
    $string = "                             <td class=\"back_build\">
                                                            <font style=\"font-weight:bold;font-size:13px;\"></font>
                                                                                    <font class=\"cost_text\" style=\"font-size:11px;\">
                                                                    <img src='images/pic5.png' align='absmiddle' alt='num1' title='num1'/> 92363                                                    </font><br />
                                                                                                            <font class=\"cost_text\" style=\"font-size:11px;\">
                                                                    <img src='images/pic7.png' align='absmiddle' alt='num2' title='num2'/> 323270                                                   </font><br />
                                                                                                            <font class=\"cost_text\" style=\"font-size:11px;\">
    
                                                                    <img src='images/pic6.png' align='absmiddle' alt='num3' title='num3'/> 129308                                                   </font><br />
                                                                                    </td>
    ";
    
    preg_match_all("/<td class=\"back_build\">\s*(.*?)\s*<\/td>/", $string, $matches);
    print_r ($matches);
    ?>
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    29
    Rep Power
    0
    Try this:
    Code:
    preg_match_all("/<td class=\"back_build\">\s*(.*)\s*<\/td>/s", $string, $matches);

    Comments on this post

    • krisrmgua agrees
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    75
    Rep Power
    11
    Ahh the 'S' at the end.. thank you so much RuleMaker i figured it was something simple.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    29
    Rep Power
    0
    No problem, just in case somebody doesn't know, the "s" flag indicates the multi-line search.
  8. #5
  9. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by RuleMaker
    No problem, just in case somebody doesn't know, the "s" flag indicates the multi-line search.
    No, it does not. The 's' flag is also called the DOT-ALL flag. The 'm' is called the MULTI-LINE flag.
  10. #6
  11. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by RuleMaker
    Try this:
    Code:
    preg_match_all("/<td class=\"back_build\">\s*(.*)\s*<\/td>/s", $string, $matches);
    Especially with the s-flag, the greedy DOT-STAR should be avoided (in this case). I'd advice the OP to at least make it reluctant as s/he already had in his/her original post:

    PHP Code:
    "/<td class=\"back_build\">\s*(.*?)\s*<\/td>/s" 
    Or (IMO) better yet, do:

    PHP Code:
    "/<td\s+class=\"back_build\">\s*([^<]*)\s*<\/td>/" // no s-flag needed 

    Comments on this post

    • krisrmgua agrees
    Last edited by prometheuzz; August 18th, 2009 at 06:15 AM.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    29
    Rep Power
    0
    Originally Posted by prometheuzz
    No, it does not. The 's' flag is also called the DOT-ALL flag. The 'm' is called the MULTI-LINE flag.
    We are talking about php, could you explain why it doesn't return any match with "m" flag while it returns exactly what it's expected with the "s" flag?
  14. #8
  15. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by RuleMaker
    We are talking about php, could you explain why it doesn't return any match with "m" flag while it returns exactly what it's expected with the "s" flag?
    I didn't say it would return a match using the MULTI_LINE flag ('m'). You just used the wrong terminology: the 's' is called the DOT-ALL flag which will let the DOT match line terminators as well (hence: DOT-ALL).
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    29
    Rep Power
    0
    Originally Posted by prometheuzz
    I didn't say it would return a match using the MULTI_LINE flag ('m'). You just used the wrong terminology: the 's' is called the DOT-ALL flag which will let the DOT match line terminators as well (hence: DOT-ALL).
    Thanks, I always thought "s" was the newline since it does match newlines, but still I'd like to know why the "m" flag, in this case, doesn't return any match even though the string is multiline.
  18. #10
  19. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by RuleMaker
    Thanks, I always thought "s" was the newline since it does match newlines, but still I'd like to know why the "m" flag, in this case, doesn't return any match even though the string is multiline.
    When using the 'm' flag, the '^' not only matches the start of the entire input string, but also matches the beginning of each line in the string. And the '$' not only matches the end of the input string, but also the and of each line.

    Example input:
    Code:
    12 34
    56 78
    90 00
    Now let's say you want to match only the numbers that are at the end of each line, you can do:

    PHP Code:
    $input '12 34
    56 78
    90 00'
    ;
    preg_match_all('/\d+$/m'$input$matches);
    print_r($matches); 
    which will produce the following output:
    Code:
    Array
    (
        [0] => Array
            (
                [0] => 34
                [1] => 78
                [2] => 00
            )
    
    )
    And when removing the 'm' flag in my example, you will see that only the "00" is matched.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    29
    Rep Power
    0
    Thanks!
  22. #12
  23. No Profile Picture
    User 165270
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    497
    Rep Power
    937
    Originally Posted by RuleMaker
    Thanks!
    You're welcome.

IMN logo majestic logo threadwatch logo seochat tools logo