我測試了這個在Firefox上,它工作正常,但在IE瀏覽器它不工作,因爲在數組的最後部分逗號。現在我怎樣才能刪除逗號使用PHP?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
}
?>
,去年逗號正在成爲「噩夢」,用一個計數器,並增加每一個循環,如果計數器的值等於計數($圖像),然後跳過打印逗號。 – Gntem 2012-07-15 09:42:14