【发布时间】:2014-11-22 23:20:55
【问题描述】:
感谢您的观看,如果这是将一串以逗号分隔的图片链接并将它们转换为图片但将列表分开以显示在网站的不同部分的正确方法,则需要一些建议。
我的代码
<?php
//the array, will be grabbing from database soon
$string = "main.jpg,extra_img_1.jpg,extra_img_2.jpg,extra_img_3.jpg,extra_img_4.jpg,extra_img_5.jpg";
//explode the whole array
$array = explode(',',$string);
//remaking the list turning it back into an array
$oldstring = '<li>'.implode('</li><li>',$array).'</li>';
// removing the first string in the commad array
array_shift($array);
//turning it back into an array without the first listed item
$newstring = '<li>'.implode('</li><li>',$array).'</li>';
//showing the old string in a listed format
echo $oldstring;
echo '<hr>';
// showing the first item in the old string
echo '<li>'.explode(',', $string)[0].'</li>';
echo '<hr>';
//once its shifted, i want to reshow the list
echo $newstring;
?>
感谢您即将提出的建议。
【问题讨论】:
-
感谢您的意见,我将编辑一些内容并让它发挥作用!
标签: php arrays explode implode