preg_match_all problem

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

  1. #1
    <p><span class="Title">Arcohe Elementary School</span><br />Elementary School<br />County: Sacramento<br />Area: A</p><p><strong>Mark Cornfield</strong>&nbsp;<br />11755 Ivie Rd.<br />Herald, CA  95638<br />&nbsp;(209) 748-2609<br /><a href="http://www.arcohe.lodinet.com" target="_blank">www.arcohe.lodinet.com</a><br /><a href="mailto:mcornfield@yahoo.com">mcornfield@yahoo.com</a></p><p>
    HTML:
    I want to find phone number and email from above I tied following code to fetch phone number but failed, can anyone help me out?

    $pattern = '/<br \/>(.*)<br \/><a href=/'; //To get school 
    preg_match_all($pattern, $myData, $matche1);
    PHP:
    Thanks
     
    dizyn, Mar 30, 2009 IP
  2. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #2
    Match mailto: ,etc .
     
    it career, Mar 30, 2009 IP
  3. kusal

    kusal Peon

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try this code

    <?php
    
    $myData = '<p><span class="Title">Arcohe Elementary School</span><br />Elementary School<br />County: Sacramento<br />Area: A</p><p><strong>Mark Cornfield</strong>&nbsp;<br />11755 Ivie Rd.<br />Herald, CA  95638<br />&nbsp;(209) 748-2609<br /><a href="http://www.arcohe.lodinet.com" target="_blank">www.arcohe.lodinet.com</a><br /><a href="mailto:mcornfield@yahoo.com">mcornfield@yahoo.com</a></p><p>';
    
    $pattern = '/\(\d{3}\)\s*\d{3}\-\d{4}/'; //To get school 
    preg_match_all($pattern, $myData, $matche1);
    
    echo $matche1[0][0];
    
    ?>
    
    Code (markup):
    This will give you phone number
    You can print_r($matche1) to see all selected phone numbers
     
    kusal, Mar 30, 2009 IP