0

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

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

4

2 回答 2

1

以这种方式使用它对我有用

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

然后在img src文件中

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

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

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

于 2021-04-20T15:33:18.223 回答
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}' />";
}
于 2013-10-11T01:01:50.800 回答