display image with preg_replace

hello,
I have this code that displays
hello (image) world
I would like to just display the image.. "hello world" is just an example and it needs to use regex because that text always changes

function display_image($content)
{
	$pattern = '/(<img [^>]*>)/i';
	$replacement = '<a href="http://google.com"">' . '\1</a>';
	$content = preg_replace($pattern, $replacement, $content);
	return $content;
}

$textes = 'hello <img src="https://www.google.com/images/errors/logo_sm.gif"/> world';
echo display_image($textes);

Open in new window

LVL 1
XK8ERAsked:
Who is Participating?
 
GaryConnect With a Mentor Commented:
function display_image($content)
{
	preg_match('/(<img.*?>)/', $content, $result);
	return $result[1];
}

Open in new window

0
All Courses

From novice to tech pro — start learning today.