phoenixx Posted August 24, 2008 Share Posted August 24, 2008 Okay, I know I just need to use preg_match_all but there's no output. Here's what I'm trying to extract. Let's say the tag on the page is <td width="230"><b>T665</b> I just want to extract the "T665" using preg_match_all echo "Getting Series Number<br>"; $data = file_get_contents("http://www.pagenamehere.php"); preg_match_all('%<b>.*?</b>|.)*?</b>%si', $data, $result, PREG_SET_ORDER); echo $result[0]; Quote Link to comment https://forums.phpfreaks.com/topic/121110-solved-extract-text-between-ltbgtltbgt-tags/ Share on other sites More sharing options...
ibechane Posted August 24, 2008 Share Posted August 24, 2008 How did you come up with that regex search string? Quote Link to comment https://forums.phpfreaks.com/topic/121110-solved-extract-text-between-ltbgtltbgt-tags/#findComment-624437 Share on other sites More sharing options...
nrg_alpha Posted August 24, 2008 Share Posted August 24, 2008 $str = ' blah blah blah <td width="230">T665</td> blah blah blah blah blah blah <td width="765">T999</td> blah blah blah'; preg_match_all('#<td[^>]*>(\w)+</td>#', $str, $matches); foreach($matches[0] as $val){ echo $val . '<br />'; } This of course assumes you close your td tag after your 'T665'...(since after your initial <td> tag, you only list T665 and nothing else). It's a very stripped down simple example to help get you started. (I used \w incase you mix numbers, undersacores and letters (both lower and uppercase)). Of course, if you need dashes or anything ele you need to reflect that in the parathesis. Quote Link to comment https://forums.phpfreaks.com/topic/121110-solved-extract-text-between-ltbgtltbgt-tags/#findComment-624518 Share on other sites More sharing options...
phoenixx Posted August 25, 2008 Author Share Posted August 25, 2008 Many Thanks. After a day and a half of no sleep... I'm surprised I even remember how to find my computer, let alone how to use it. Quote Link to comment https://forums.phpfreaks.com/topic/121110-solved-extract-text-between-ltbgtltbgt-tags/#findComment-625203 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.