Solved

display image with preg_replace

Posted on 2014-01-07
1
172 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 500 total points
ID: 39763019
function display_image($content)
{
	preg_match('/(<img.*?>)/', $content, $result);
	return $result[1];
}

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

738 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