Jump to content

[SOLVED] Extract Text Between <b></b> Tags


phoenixx

Recommended Posts

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];

 

 

$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.