Regex advise

Discussion in 'Programming' started by mumfry, Jun 17, 2010.

  1. #1
    hey guys
    how do i capture this value 23:03 using regular expression, from a code like this

    <div style="float: left; width: 70px;">
    23:03<br>
    </div>

    if it was all on the same line it would be no problem but the line breaks are whats throwing me off.
    if it was a single line like so
    <div style="float: left; width: 70px;">23:03<br></div>
    then i would use this
    preg_match_all("/<div style=\"float: left; width: 70px;\">(.*)<br></div>/",$,$);

    any ideas will be greatly appreciated
    thanks
     
    mumfry, Jun 17, 2010 IP
  2. flexdex

    flexdex Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $subject =<<<AAA
    <div style="float: left; width: 70px;">
    21:01<br>
    </div>
    <div style="float: left; width: 70px;">
    22:02<br>
    </div>
    <div style="float: left; width: 70px;">
    23:03<br>
    </div>
    AAA;
    preg_match_all('%<div\sstyle="float:\s*left;\s*width:\s*70px;">\s*(\d\d:\d\d)\s*<br>\s*</div>%simx', $subject, $result, PREG_PATTERN_ORDER);
    foreach ($result[1] as $time) {
    	echo "$time\n"; 
    }
    
    PHP:
     
    flexdex, Jun 17, 2010 IP
  3. mumfry

    mumfry Active Member

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    wow
    you are amazing my man
    great solution
    worked like a charm
     
    mumfry, Jun 17, 2010 IP