Jump to content

Preg match question - urgent help needed


denhamd2

Recommended Posts

ok, and do you want complete code returned or just partial code?  I'll explain the question.  Do you want the <table> tag along with the first 7 <tr> tags, or just the 7 <tr> tags, or the <table>, the first 7 <tr> tags and then everything after the last <tr> tag?

Long winded, but hopefully makes sense...

Regards
Huggie
[code]
<pre>
<?php

$html = <<<HTML
<table>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr><td>4</td></tr>
<tr><td>5</td></tr>
<tr><td>6</td></tr>
<tr><td class="something">7</td></tr>
<tr><td>8</td></tr>
<tr><td>9</td></tr>
<tr><td>10</td></tr>
</table>
HTML;

preg_match_all('%<tr[^>]*>(.*?)</tr>%', $html, $matches);
$first_7 = array_slice($matches[1], 0, 7);
print_r($first_7);

?>
</pre>
[/code]

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.