Hello, I have got links field in the database. The entries are like this: http://webpicshot.com/images/0vhoxwbxxoaicir13la.jpg;http://webpicshot.com/images/i2qf04wgmwstdukqpdt.jpg;http://rapidshare.com/files/106224452/TenaciousDFhergently.avi ; PHP: I have got image link urls and normal urls. Every url is seperated with ";" What can I do to show the image for the image url instead of the url? I want to display image instead of the url. I just use $row['links'] PHP: to show the links. Thanks
You need to split up the url's and then display the images. Something like: $imageArray = array('jpg','gif','png'); $urls = explode(';',$row['links']); foreach($urls as $url) { if(in_array(substr($url,3),$imageArray)) { echo '<img src="'.$url.'" />'; } } PHP:
Thank you for your reply. I tried your code but it did not work. It is just saying Array instead of image or links. Thanks
if(in_array(substr($url,3),$imageArray)) for the line above replace the number 3 with minus 3 (-3) tell me what happens
$imageArray = array('jpg','gif','png'); $urls = explode(';',$row['links']); foreach($urls as $url) { if(in_array(substr($url,(-3)),$imageArray)){ echo '<img src="'.$url.'" />'; } } PHP: This worked kind of. The problem is if there is normal link other than image in the field , it does not display. Any idea how can i show normal links as well as image links? Thanks
ok add the following lines to the code if(in_array(substr($url,(-3)),$imageArray)){ echo '<img src="'.$url.'" />'; } else { echo '<a href='.$url.'>'.$url.'</a>'; } tell me what happens
Last one more question. What about if i want to show the first image and rest of the urls as links. Say there are 4 urls. First 2 are images and last 2 are links. I want to show first image url as image and other 3 urls as url. this is what i have got now. $imageArray = array('jpg', 'gif', 'png'); $urls = explode(';', $row['links']); foreach ($urls AS $url) { if (in_array(substr($url, -3), $imageArray)) { echo "<img src=\"$url\" /><br /><br />"; } else { echo '<a href='.$url.'>'.$url.'</a><br />'; } } PHP:
ok try this code $counter = 0; foreach($urls as $url) { if(in_array(substr($url,-3),$imageArray)) { if($counter==0) { echo "<img src=\"$url\" /><br /><br />"; $counter++; } else { echo '<a href='.$url.'>'.$url.'</a><br/><br/>'; } }
Thank you very much. it worked, this code does not make my site run slow, does it? Thanks $imageArray = array('jpg', 'gif', 'png'); $urls = explode(';', $row['links']); $counter = 0; foreach ($urls AS $url) { if (in_array(substr($url, -3), $imageArray)) { if($counter==0) { echo "<img src=\"$url\" /><br /><br />"; } $counter++; } else { echo '<a href='.$url.'>'.$url.'</a><br />'; } } PHP: