Hi is there any function that can limit or remove more than 1 img tags in a string? <?php $string = "<img src=1> this is text <img src=2> <img src=3> here\'s some text <img src=4>"; echo limitImage($string); function limitImage { // Some function to do remove more than 1 img tags .. } ?> PHP: thanks..
Find out how many img tags there are in the string. If there is more than one, change the first one to something else, strip the rest of the image-tags and put back in the first one. I cant write any code right now, I have a baby watching Totoro in my arm, but the above should be pretty easy.
You can use preg_replace() Please write what you exactly want "echo limitImage($string);" to show with your example if you want more help.
Hi.. I want to find all image tags in the string, keep the first image (img tag) and remove all others. basically to show just one image..if string contains 2 or more images..
function limitImage($string) { $string = preg_split('/(<img[^>]+>)/i', $string, 2, PREG_SPLIT_DELIM_CAPTURE); return $string[0] . $string[1] . strip_tags($string[2]); } PHP: