I have a string that contains image tags. I need to add a width to all image tags, except if they are smilie images. So an image like this on should get a width added: <img src="someurl... should become: <img width="200" src="someurl... PHP: Smilie-images will look like this in the string: <img src="/images/smilies/someurl.. PHP: They should not get the width added. How can I do this? Adding the width tag to the images is easy with replacements. But it also adds it to the smiley images.
You use preg_match to see if "smilies" exists in the string (I don't know the code off hand for this, just lookup the function on php.net). Then something like this: if(!preg_match(whatever parameters)) { $imgcode = ereg_replace("<img", "<img width=\"200\"", $imgcode); } PHP: I may have the parameters mixed up for ereg_replace, but that's the basics of how to do it.
Yeah, okay. But the string can contain more than one image tag. So I need to go through the tags one by one and check if it's a smilie or not...
$code = preg_replace('#<img src="([/images/smilies]^)">#iUe','<img width="200" src="\\l">',$code); PHP: Not sure if the ^ should be before or after to exclude. Peace,