Hi, What about: $string = preg_replace("/(<td)[^>]*/","\\1 id={$counter}",$string);
atur ----- Original Message ----- From: "Tobias Talltorp" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, September 09, 2003 6:35 PM Subject: [PHP] PREG-pattern, help needed > 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php