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:
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:
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?
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> <br />1402 Sycamore Ave<br />Tustin, CA 92780<br /> (714) 730-7360<br /><br /><a href="mailto:kbruner@tustin.k12.ca.us">kbruner@tustin.k12.ca.us</a></p><p> </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:
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> <br />1402 Sycamore Ave<br />Tustin, CA 92780<br /> (714) 730-7360<br /><br /><a href="mailto:kbruner@tustin.k12.ca.us">kbruner@tustin.k12.ca.us</a></p><p> </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: