Jump to content

Replace text with altering HTML


texelate

Recommended Posts

Hi

I'd like to perform a str_replace on some HTML but I don't want any of the HTML tages to be affected.  For example if the original string has:

[code]$html = '<div><img src="/a_picture_of_me.jpg" alt="" /> A picture of me</div>';[/code]

And I do a str_replace to change "picture" to "Jon" I will end up with:

[code]$html = '<div><img src="/a_picture_of_Jon.jpg" alt="" /> A picture of Jon</div>';[/code]

Is there any way I can replace it without affecting any HTML tags - so I'd end up with:

[code]$html = '<div><img src="/a_picture_of_me.jpg" alt="" /> A picture of Jon</div>';[/code]

Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/26820-replace-text-with-altering-html/
Share on other sites

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.