preg_replace with auto-increment?

Started by Cadish, August 28, 2004, 06:23:30 PM

Previous topic - Next topic

Cadish

Hi,

Is it possible to add in the preg_replace an auto-increment?

So, e.g., if you have this:

<td></td>
<td></td>
<td></td>
<td></td>
<td></td>


Is it possible to convert this to the following with just one preg_replace (or something else):

<td name="td1"></td>
<td name="td2"></td>
<td name="td3"></td>
<td name="td4"></td>
<td name="td5"></td>


Thanks!
Cadish

[Unknown]

You can use ~~e.....  basically:

'~<td>~e' ==> '\'<td id="td\' . ($inc++) . \'">\''

-[Unknown]

Cadish

#2
You just keep amazing me!! Great man!!

Thanks a lot!

Cadish

The problem has changed a bit...

So, I start with this:
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>


And I want to have this at the end:

<td id="td1" onmouseover="document.getElementById('td2').className='mouseover';"></td>
<td id="td2" onmouseover="document.getElementById('td4').className='mouseover';"></td>
<td id="td3" onmouseover="document.getElementById('td6').className='mouseover';"></td>
<td id="td4" onmouseover="document.getElementById('td8').className='mouseover';"></td>
<td id="td5" onmouseover="document.getElementById('td10').className='mouseover';"></td>
<td id="td6" onmouseover="document.getElementById('td12').className='mouseover';"></td>
<td id="td7" onmouseover="document.getElementById('td14').className='mouseover';"></td>
<td id="td8" onmouseover="document.getElementById('td16').className='mouseover';"></td>
<td id="td9" onmouseover="document.getElementById('td18').className='mouseover';"></td>


Thanks!
Cadish

[Unknown]

'~<td>~e' ==> '\'<td id="td\' . ($inc) . \'" onmouseover="document.getElement(\\\'td\' . ($inc++ * 2) . \'\\\').className = \\\'mouseover\\\';">\''

-[Unknown]

Advertisement: