2013-10-10 80 views
0

我正在选择从数据库中的行,并使用下面的各图像分离(全部在一列)使用在PHP爆炸到

$images = explode(',',$result['images']); 

的多个图像的一个串中分离然后以显示我使用一个图像这个HTML/PHP代码:

<img src="/img/project-gallery/'.strtr($images[0],'[]','""').'" 

但它显示像下面

<img src="/img/project-gallery/" 5_b.jpg""=""> 

我如何使它显示升艾克图像是假设

在我的数据库,影像都像一列:

[image1.jpg],[image2.jpg],[image3.jpg]等等

+0

为什么不只是做'SUBSTR($图像,1, -1)' –

+0

我怀疑逗号后面有空格,你需要删除它们。此外,你不应该用引号替换括号,你应该删除它们。 – Barmar

+0

...我的意思是循环中的子串。 –

回答

0
$temp = explode(',',$result['images']); 

foreach($temp as $image){ 
    $images[]="/img/project-gallery/".trim(str_replace(array('[',']') ,"" ,$image)); 
} 
//now your array of images cotaines to full source to each image 

foreach($images as $image){ 
    echo "<img src='{$image}' />"; 
}