All pastes #924356 Raw Edit

img is everything

public php v1 · immutable
·published 2008-03-01 07:37 UTC
rendered paste body
//I use preg_replace_callback which calls a user defined function ever time it finds a match. In that function I check the $firstTime global variable. If its set it won't blank out the img. Afterward I search and remove any empty <a> tags.<?php$string = $item->get_content();$firstTime = true;$pattern = '/<img[^>]+?[>]/is';$string = preg_replace_callback($pattern, 'imgOff', $string);// remove empty <a> tags$pattern = '/<a[^>]*?[>]<\/a>/si';$replacement = '';$string = preg_replace($pattern, $replacement, $string);	function imgOff($matches)// remove all but first img tag{	global $firstTime;	if ($firstTime)	{		$firstTime = 0;		return $matches[0]; // skip first img tag	}	return '';}?>