express problem

Discussion in 'PHP' started by dizyn, Mar 4, 2008.

  1. #1
    Hi want to fetch:
    <font style="font-weight:bold;">Chicago Cubs</font> <br/>

    vs

    <br />
    Milwaukee Brewers

    Here is my code.
    			$title = '/<div class="listevent">(.*) <\/div>/';
    			preg_match_all($title, $value, $mat);
    PHP:
    It returns me empty array, any help


    <div class="list1">
    	<div class="listevent"><font style="font-weight:bold;">Chicago Cubs</font> <br/>
    	
    		vs 
    	
          <br />
          Milwaukee Brewers</div>
    	<div class="listdate">March 4, 2008<br/>1:05 pm<br />
    	  <!--Tuesday, 7:05 pm--></div>
    
    	<div class="listvenue">
    		<strong>Hohokam Park</strong><br />
    	 Mesa, AZ	  	  </div>
    Code (markup):


    at started i tried to fetch:
    
    <div class="list1">
    	<div class="listevent"><font style="font-weight:bold;">Chicago Cubs</font> <br/>
    	
    		vs 
    	
          <br />
          Seattle Mariners</div>
    
    	<div class="listdate">March 7, 2008<br/>1:05 pm<br />
    	  <!--Tuesday, 7:05 pm--></div>
    	<div class="listvenue">
    		<strong>Hohokam Park</strong><br />
    	 Mesa, AZ	  	  </div>
    	<div class="listticket">
    	
    	 <a href="/sports/buy_tickets/569614/" >View Tickets</a>	</div>
    
    	<div style="clear:both;">
    	<img src="/img/spacer.gif" width="1" height="1" border="0" />	</div>
    	
    </div>
    Code (markup):
    but end up with only
    
    <div class="list1">
    	<div class="listevent"><font style="font-weight:bold;">Chicago Cubs</font> <br/>
    	
    		vs 
    	
          <br />
          Milwaukee Brewers</div>
    	<div class="listdate">March 4, 2008<br/>1:05 pm<br />
    	  <!--Tuesday, 7:05 pm--></div>
    
    	<div class="listvenue">
    		<strong>Hohokam Park</strong><br />
    	 Mesa, AZ	  	  </div>
    
    Code (markup):
    rest is missing
    i used:
    
    	$pattern = '/<div class="list(\d)">(.*)<\/div>/msU';
    	preg_match_all($pattern, $data, $matche1);
    
    
    PHP:
     
    dizyn, Mar 4, 2008 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    You are confused because of the pattern modifier and greediness.

    Greedy - Will start at first <div> up to the last </div>
    Ungreedy - Will start at next <div> to the next </div>

    You should read about the s, m and U modifiers:

    http://us2.php.net/pcre.pattern.modifiers

    Peace,
     
    Barti1987, Mar 4, 2008 IP