keep HTMLformat after replace some text (using PHP and JS)

Posted by Sadi on Stack Overflow See other posts from Stack Overflow or by Sadi
Published on 2010-04-01T21:05:06Z Indexed on 2010/04/12 3:23 UTC
Read the original article Hit count: 326

I would like modify HTML like

I am <b>Sadi, novice</b> programmer.

to

I am <b>Sadi, learner</b> programmer.

To do it I will search using a string "novice programmer". How can I do it please? Any idea?

Thank you

Sadi


More clarification:

I get some nice reply with possible solution. But please keep posting if you have any idea in mind.

I would like to more clarify the problem just in case anyone missed it. Main post shows the problem as an example scenario.

1) Now the problem is find and replace some string without considering the tags. The tags may shows up within a single word. String may contain multiple word. Tag only appear in the content string or the document. The search phrase never contain any tags.

We can easily remove all tags and do some text operation. But here the another problem shows up.

2) The tags must be preserve, even after replacing the text. That is what the example shows.

Thank you Again for helping

© Stack Overflow or respective owner

Related posts about php

Related posts about html