PREG-pattern, help needed
| From: | Tobias Talltorp | Date: | Tue, 09 Sep 2003 16:35:36 +0000 |
| Subject: | PREG-pattern, help needed | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-162087@lists.php.net to get a copy of this message | ||
I need help with a preg-pattern for preg_replace_callback().
I need to match <td(+all properties)> and replace them with <td
id=$counter>.
This is as far as I have come in my code:
<?php
$html = '<table border=1 id="myTable">
<tr>
<td>
<table border=1>
<tr>
<td width=20>tabell2 cell1</td>
<td width=40>tabell2 cell2</td>
</tr>
</table>
</td>
<td>första cell i rad två</td>
<td>Detta är den sista</td>
</tr>
</table>';
$counter = 0;
function bla($matches) {
global $counter;
$counter++;
return "<td id=\"theId".$counter."\">";
}
// this pattern is all wrong, since it matches and replaces all tags
echo preg_replace_callback("|(<[td][^>]+>)|i", "bla", $html);
?>
Any thoughts?
// Tobias