Jump to content

convert link to image


phorcon3

Recommended Posts

so, for example i have a text like this:

 

blah blah blah... blah blah ..check out this image: http://www.google.com/intl/en_ALL/images/logo.gif ..blah blah...

 

and now i wanna use a php function to:

 

a) find the urls within the text (if there are any)

b) allow only jpg, gif, png, bmp formats

 

<?php

if(eregi('(.)+\\.(jpg$|gif$|png$|bmp$)', $string))

?>

 

c) if image, display <img src="LINK HERE" border="0" />

d) if url, display <a href="LINK HERE" target="_blank">LINK HERE</a>

 

id appreciate any help on this, thanks;)

Link to comment
https://forums.phpfreaks.com/topic/100831-convert-link-to-image/
Share on other sites

so if I read this right you want

 


if (eregi('(.)+\\.(jpg$|gif$|png$|bmp$)', $string) {
echo '<img src="LINK HERE" border="0" />';
} else {
echo '<a href="LINK HERE" target="_blank">LINK HERE</a>';
}

 

seems like you might want to think through your question a little more, this just seems way to simple (assuming your brain wasn't tapioca when you posted this)

yah, but the problem is that this would remove all the text

 

hi, i just wanted you to check out this image: http://www.google.com/intl/en_ALL/images/logo.gif ...awesome, huh?

 

and what the code should do is find the url and convert it.

 

so it would display:

 

hi, i just wanted you to check out this image: <img src="http://www.google.com/intl/en_ALL/images/logo.gif" border="0" /> ...awesome, huh?

 

hope this makes sense?

php file:

 

<?php

echo convert_url($b['comment']);

?>

 

function file:

 

<?php

function convert_url($string)
{
$string = trim($string);

//find the URL within the text
//is image? (jpg, gif, png, bmp) => <img src="" border="0" />
//is link? => <a href="" target="_blank"></a>

return $string;
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.