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
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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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;
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.