Re: Replacing text on page, but not in <img> tags

From: Date: Thu, 06 Nov 2003 22:48:39 +0000
Subject: Re: Replacing text on page, but not in <img> tags
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-168788@lists.php.net to get a copy of this message
Taylor York wrote:
Lets say im trying to replace every occurance of 'hello' with '<b>hi</b>'.
Here's something that's probably close to what you want. Something else you need to worry about besides <img> tags is what if the word "hello" appears in a <a> tag? within Javascript? This will match anything outside of tags, at least, and then add in the <strong> tags around "hello". function callback($match) { return str_replace('hello','<strong>hello</strong>',$match[0]); } $new_str = preg_replace_callback('/>([^<]+)</','callback',$str); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#168788) next »