Jump to content

Find, replace and increase


brosjr

Recommended Posts

Good morning all,

 

Please, I hope someone could help me to solve this, I searched all over and I can't figure out how to do it.

 

I have a text with many paragraphs started with <P> tags on it and I need to replace then to <P class=X>, where X has to be increased from 0, like <P class=0>, <P class=1>, <P class=2>, and so on until the last <P> tag.

 

I tried many solutions and I just got replaced the <P> tags for <P class=0>, <P class=0>, <P class=0>.

 

Really thankx.

Danilo Jr.

Link to comment
https://forums.phpfreaks.com/topic/220922-find-replace-and-increase/
Share on other sites

:D Searching and trying a little bit more, I found a solution that fitted weel for my application:

 

$count = count(explode("<P>", $text));

 

$pieces= explode("<P>", $text);

$t = 0;

while ($t < $count){

$teste.= substr_replace($pieces[$t],"<P class=$t>",0,0);

$t = $t+1;

}

 

echo $teste;

 

Salathe, I'm new on this stuff, and I tryed many solutions before I got this.

 

Thankx

Danilo Jr

  • 4 weeks later...

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.