php express problem

Discussion in 'PHP' started by dizyn, Mar 13, 2009.

  1. #1
    I wanted to now fetch "Middle School" from this string but getting any output, from where I can get help in it. I think my code it correct but its not working, is there any formula for this?
    Here is my code

    $data = '<p><span class="Title">A.G. Currie Middle School</span><br>Middle School<br>County: Orange<br>Area: F</p>';
        $pattern = '/<\/span><br>([A-Za-z ]+)<br>/'; //To get school   
        preg_match_all($pattern, $data, $matche1);
        echo '<pre>';   print_r($matche1);  exit;
    PHP:
     
    dizyn, Mar 13, 2009 IP
  2. dizyn

    dizyn Active Member

    Messages:
    251
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    This worked for school
    $pattern = '/<\/span><br \/>([A-Za-z ]+)<br \/>/'; //To get school
    PHP:
    I tired this but failed:

    $pattern = '/<br>County: ([A-Za-z ]+)<br>/'; //To get county
    PHP:
    Tried this for area but failed:

    $pattern = '/<br>Area: ([A-Za-z ]+)<\/p>/'; //To get area
    PHP:
     
    dizyn, Mar 13, 2009 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    I'm not really sure what you are asking - the code works fine - it outputs the following:

    
    Array
    (
        [0] => Array
            (
                [0] => 
    Middle School
    
            )
    
        [1] => Array
            (
                [0] => Middle School
            )
    
    )
    
    Code (markup):
    Was that not what you were expecting?
     
    PoPSiCLe, Mar 13, 2009 IP
  4. dizyn

    dizyn Active Member

    Messages:
    251
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    Its working problem is with
    county and area, 2nd and 3rd pattern in my previous post.
     
    dizyn, Mar 13, 2009 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    This works for Area:
    
        $pattern = '/<br>([A-Za-z :]+)<\/p>/'; //To get area
    
    Code (markup):
     
    PoPSiCLe, Mar 13, 2009 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    And this works for County:

    $pattern = '/<br>(County[A-Za-z :]+)<br>/'; //To get county
    PHP:
     
    PoPSiCLe, Mar 13, 2009 IP
  7. dizyn

    dizyn Active Member

    Messages:
    251
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #7
    Sorry here the final code when i try this it gives me blank output.
    
    	$data = '<span class="subtitle">Results Detail</span><br><br><table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;"><tr><td><p><span class="Title">A.G. Currie Middle School</span><br />Middle School<br />County: Orange<br />Area: F</p><p><strong>Kevin Bruner</strong>&nbsp;<br />1402 Sycamore Ave<br />Tustin, CA  92780<br />&nbsp;(714) 730-7360<br /><br /><a href="mailto:kbruner@tustin.k12.ca.us">kbruner@tustin.k12.ca.us</a></p><p>&nbsp;</p></td></tr></table><br><br />';
    	$pattern = '/<br>(County[A-Za-z :]+)<br>/'; //To get county 
    	preg_match_all($pattern, $data, $matche1);
    	echo '<pre>';	print_r($matche1);	exit;
    
    
    PHP:
     
    dizyn, Mar 13, 2009 IP
  8. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #8
    You need to alter the <br> to <br \/> in the code, as this:
    
    <?php
    
    $data = '<span class="subtitle">Results Detail</span><br><br><table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;"><tr><td><p><span class="Title">A.G. Currie Middle School</span><br />Middle School<br />County: Orange<br />Area: F</p><p><strong>Kevin Bruner</strong>&nbsp;<br />1402 Sycamore Ave<br />Tustin, CA  92780<br />&nbsp;(714) 730-7360<br /><br /><a href="mailto:kbruner@tustin.k12.ca.us">kbruner@tustin.k12.ca.us</a></p><p>&nbsp;</p></td></tr></table><br><br />';
        $pattern = '/<br \/>(County[A-Za-z :]+)<br \/>/'; //To get county
        preg_match_all($pattern, $data, $matche1);
        echo '<pre>';   print_r($matche1); exit;
    ?>
    
    PHP:
     
    PoPSiCLe, Mar 13, 2009 IP