在 PHP 中使用爆炸来分隔多个图像的字符串


using explode in php to separate a string of multiple images

>我正在从数据库中选择行并使用以下内容来分隔每个图像(全部在一列中(

$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]等...

这种方式使用它对我有用

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

然后在 img src 文件中

<img src="xxxx/xxx/<?php echo strtr($images[0],'[]',''); ?>">

它将只选择一个图像文件,只要您的图像在数据库中排列在一列中,例如

[图像1.jpg],[图像2.jpg],[图像3.jpg]等...

$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}' />";
}