不需要的\字符

不需要的\字符

问题描述:

php code:

<?php 
echo json_encode(glob("photos-".$_GET["folder"].'/*.jpg'));
?>

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代码: p>

 &lt;?php 
echo json_encode  (glob(“photos  - ”。$ _ GET [“folder”]。'/ *。jpg')); 
?&gt; 
  code>  pre> 
 
 

它返回: p>

  [ “照片 -  ANIMAUX \ /ani-01.jpg”, “照片 -  ANIMAUX \ /ani-02.jpg”,“照片-ANIMAUX \ / ANI-02B  .JPG “ ”照片 -  ANIMAUX \ /ani-03.jpg“, ”照片 -  ANIMAUX \ /ani-04.jpg“, ”照片 -  ANIMAUX \ /ani-05.jpg“,” 照片-ANIMAUX \ / ANI  -06.jpg “ ”照片 -  ANIMAUX \ /ani-07.jpg“, ”照片 -  ANIMAUX \ /ani-08.jpg“, ”照片 -  ANIMAUX \ /ani-09.jpg“,” 照片,ANIMAUX \  /ani-10.jpg","photos-animaux\/ani-11.jpg","photos-animaux\/ani-12.jpg","photos-animaux\/ani-13.jpg","photos-  animaux \ /ani-14.jpg“] 
  code>  pre> 
 
 

除了\字符之外,几乎完美无缺......它来自哪里? p>

以下是调用它的jquery代码: p>

  $。get('photolister.php',
 {'folder':$(this  ).attr('href')},
 function(data){startSlideshow(data); console.log(data);} 
); 
  cod  e>  pre> 
  div>

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...