phorcon3 Posted April 12, 2008 Share Posted April 12, 2008 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;) Quote Link to comment Share on other sites More sharing options...
amites Posted April 12, 2008 Share Posted April 12, 2008 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) Quote Link to comment Share on other sites More sharing options...
phorcon3 Posted April 12, 2008 Author Share Posted April 12, 2008 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? Quote Link to comment Share on other sites More sharing options...
phorcon3 Posted April 12, 2008 Author Share Posted April 12, 2008 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; } ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted April 12, 2008 Share Posted April 12, 2008 eregi_replace Quote Link to comment Share on other sites More sharing options...
phorcon3 Posted April 17, 2008 Author Share Posted April 17, 2008 uh, duh. thanks alot!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.