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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.