开发者

unwanted \ character

开发者 https://www.devze.com 2022-12-10 17:26 出处:网络
php code: <?php echo json_encode(glob(\"photos-\".$_GET[\"folder\"].\'/*.jpg\'));开发者_如何学Python

php code:

<?php 
echo json_encode(glob("photos-".$_GET["folder"].'/*.jpg'));开发者_如何学Python
?>

it return :

["photos-animaux\/ani-01.jpg","photos-animaux\/ani-02.jpg","photos-animaux\/ani-02b.jpg","photos-animaux\/ani-03.jpg","photos-animaux\/ani-04.jpg","photos-animaux\/ani-05.jpg","photos-animaux\/ani-06.jpg","photos-animaux\/ani-07.jpg","photos-animaux\/ani-08.jpg","photos-animaux\/ani-09.jpg","photos-animaux\/ani-10.jpg","photos-animaux\/ani-11.jpg","photos-animaux\/ani-12.jpg","photos-animaux\/ani-13.jpg","photos-animaux\/ani-14.jpg"]

Which is ALMOST perfect, except for the \ character... Where did it come from?

Here is the jquery code that calls it:

$.get(  'photolister.php',
                    {'folder' : $(this).attr('href')},
                    function(data){startSlideshow(data);console.log(data);}
                );


PHP is automatically escaping the string.

You can use stripslashes to remove the unwanted slashes.

You could also use the GLOB_NOESCAPE flag in your glob() call.

PHP Manual: stripslashes
PHP Manual: glob


Maybe it's escaping the '/' out?

anyways, it shouldn't matter, when JS parses the json, it probably will ignore it...

0

精彩评论

暂无评论...
验证码 换一张
取 消