On my site the code below takes any images posted by a user that is over 360px in width and resizes it so the max width stays at 360px, it then puts a link on the bottom of the image clickable to view original size. When an image is posted by a user that is like this: it works just fine but when users post it like this: it does not resize the image. It looks like anytime there is no quotes " or ' it does not work. Can someone look through the code and fix this so even if you don't enter the quotes it will still resize the image.
The problem lies here (in bold)... preg_match_all("/<img.*?src=(\"|')([^']*?)(\"|').*?>/", $row[comment], $matches); You're only checking ones that use ' or ", you'll have to either remove that or throw a ? after the ). As for the 2nd time it tries to find the ' or ".. you'll have to change that one to ( )? Here's what I'd change the top half of that code to (ending right before you set $image[tag]: #Image search preg_match_all("/<img.*?src=(?:\"|')?([^ >'\"]+)(?:[^>]*)>/i", $row[comment], $matches); #[0] Contains the image tags, [1] Contains the urls foreach($matches[0] as $key=>$value){ $regexw = "/width=(?:\"|')?([0-9]+)/i"; $regexh = "/height=(?:\"|')?([0-9]+)/i"; preg_match_all($regexw,$value, $width); preg_match_all($regexh,$value, $height); $img[src] = $matches[1][$key]; $img[width] = $width[1][0]; $img[height] = $height[1][0]; PHP: First, it checks if it does have ' or " and if it doesn't, says oh well. Also, I put ?: in the front of most of my ( ) which means to not add it into the array of matches (since it's not needed). It then checks the image's source by grabbing everything until it hits ', ", a space, or >. It then continues grabbing the rest of the tag. I did the same thing with your width & height grabbers, made them not care if there's ' or ". You really didn't need anything else after grabbing [0-9] from the width/height so I stopped checking there.