Jump to content

[SOLVED] Strip all content before and after certain strings, Regex maybe?


Dale_G

Recommended Posts

Okay, there is webpage which I'm getting through file_get_contents.

 

The part I want to get is this

 

<td align="right" class="head-row">
<div id="numbertext">745</div>
<br><br>
<div id="numbertext">873</div>
<br><br>
<div id="numbertext">2324</div>
<br><br>
</td>

 

But, no all of that, you see the number 745? I'd need to be able to get that number by itself. Don't really need the other numbers, just the first number between the <div id="numbertext"> and the </div> tags. The thing is...the div '<div id="numbertext">' appears multiple times before AND after this block of code, but the '<td align="right" class="head-row">' only appears once, which is why I BELIEVE it needs to be..focused on.

 

Not sure though, basically..you see from the above code, I need to get that number 745 by itself. Thanks guys! ;D

<?php

$html = <<<HTML
<td align="right" class="head-row">
<div id="numbertext">745</div>
<br><br>
<div id="numbertext">873</div>
<br><br>
<div id="numbertext">2324</div>
<br><br>
</td>
HTML;
$replace = "|\\2|";
$new = eregi_replace("<div ([a-zA-Z0-9 \"=]+)>([0-9]+)</div>", $replace, $html);
$new = explode("|", $new);
foreach ($new as $v) {
  	if (is_numeric($v)) {
  		$numbers[] = $v;
  	}
}
print_r($numbers);
?>

 

Worked for me.

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.