gerkintrigg Posted November 14, 2009 Share Posted November 14, 2009 I have the following code: <?php $html = '<b alt="bum">The word "bum" needs replacing with something less offensive.</b>'; $pattern = '@\>(.+?)\<@'; $replacement = '>'.str_replace('bum','bottom',$html).'<'; $page = preg_replace($pattern, $replacement, $html); echo $page; ?> If you run it, you'll find that the word "bum" is replaced with "bottom" which is what I want, but the original alt tag (and I know it's nonsense HTML) is also being duplicated, with the duplicate being replaced... though I don't know why it's showing twice... I just want to keep the original HTML but replace its contents... any suggestions? Link to comment https://forums.phpfreaks.com/topic/181488-pre_replace-within-html/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.