?
Solved

display image with preg_replace

Posted on 2014-01-07
1
Medium Priority
?
177 Views
Last Modified: 2014-01-07
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

0
Comment
Question by:XK8ER
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 39763019
function display_image($content)
{
	preg_match('/(<img.*?>)/', $content, $result);
	return $result[1];
}

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question