I need a small code snippet function to use on a certain database cell when calling my loop, what I need it to do is parse the code, if it finds an image link amend certain code to it, if not, return original code. Unfortunately this is beyond my scope of expertise so again I come to the wise programmers of digitalpoint for assistance. Please direct me in anyway you can. Thank you
If you provide a sample of what your image links look like without the added code, and a sample of what they should look like with the added code, then someone will be able to help you.
well the added code can be anything, the image link is just a plain image link. before being entered http://www.yaya.com/funny.jpg after <a href="http://www.yaya.com/funny">whatever</a>
sorry for not stating this before but there will be more text in the submission as well. eg Hi my name is danny and I love to fish http://www.dannylovestofish.com/imagefish.jpg output Hi my name is danny and I love to fish <img src="http://www.dannylovestofish.com/imagefish.jpg">
<?php $submission = <<<TEXT Hi my name is danny and I love to fish http://www.dannylovestofish.com/imagefish.jpg TEXT; $imagelink = preg_replace("/(http:\/\/www\.[a-z0-9-]*\.[a-z\.]{2,6}\/[a-z0-9-\/]*\.[a-z]{3,5})/i", "<img src=\"$1\">", $submission); echo $imagelink; ?> PHP:
It works like a charm except if im grabbing a link from somewhere like imageshack, for example. http://img705.imageshack.us/img705/1342/hahahalulz.jpg or http://img195.imagevenue.com/img.php?image=81164_n506933898_580553_2577_122_842lo.jpg does not display anything yet http://www.anything.com/hahaha.jpg would display an image. any thoughts?? Ive been messing with it for over an hour but I just cant understand it.
Try this (untested): <?php $submission = <<<TEXT Hi my name is danny and I love to fish http://img195.imagevenue.com/img.php?image=81164_n506933898_580553_2577_122_842lo.jpg TEXT; $imagelink = preg_replace("#(http://([^/]+)[^\s]+)#", "<img src=\"$1\">", $submission); echo $imagelink; ?> PHP: