我在 Firefox 上对此进行了测试,它工作正常,但在 IE 中它不起作用,因为数组的最后一部分有逗号。现在如何使用 php 删除逗号?
实际结果:
{image : 'folder/pic1.jpg', title : '', thumb : 'folder/pic1.jpg', url : ''},
{image : 'folder/pic2.jpg', title : '', thumb : 'folder/pic2.jpg', url : ''},
{image : 'folder/pic3.jpg', title : '', thumb : 'folder/pic3.jpg', url : ''},
预期结果:
{image : 'folder/pic1.jpg', title : '', thumb : 'folder/pic1.jpg', url : ''},
{image : 'folder/pic2.jpg', title : '', thumb : 'folder/pic2.jpg', url : ''},
{image : 'folder/pic3.jpg', title : '', thumb : 'folder/pic3.jpg', url : ''}
代码:
<?php
$directory = "pic/";
$images = glob("".$directory."{*.jpg,*.JPG,*.PNG,*.png}", GLOB_BRACE);
if ($images != false)
{
?>
<script type="text/javascript">
jQuery(function($){
$.supersized({
slideshow: 1,//Slideshow on/off
autoplay: 1,//Slideshow starts playing automatically
start_slide: 1,//Start slide (0 is random)
stop_loop: 0,
slides: [// Slideshow Images
<?php
foreach( $images as $key => $value){
echo "{image : '$value', title : '', thumb : '$value', url : ''},";
}
?>
],
progress_bar: 1,// Timer for each slide
mouse_scrub: 0
</script>
<?php
}
?>