duanniying2342 2014-05-23 18:22
浏览 38
已采纳

PHP返回是添加空格,即使是trim()

I have a function that should report a boolean, but it's adding spaces to the front of the string. Even with trim(), the spaces remain... What is causing this?

PHP

function a($v){
  $r = is_file($v) ? 1 : 0;
  return(trim($r));
}

JS

$.ajax(url+query,{ success:function(data){ return(data); } });

Output

    1

Update

I'm invoking using $_GET, calling the function depending on the parameter past in the query. This is the first time I've had this issue, everything else works fine. I don't think this has any thing to do with spaces in the file - it doesn't occur anywhere else, and I'm only returning what's in the function..

  • 写回答

3条回答 默认 最新

  • drl92080 2014-05-23 18:26
    关注

    You must have spaces in the PHP files you include. You must encode your file in UTF8 without Bom. And remove "?>" at the end of your files.

    Verify all your files, or you can use :

    function a($v){
      $r = is_file($v) ? 1 : 0;
      ob_clean();
      return $r;
    }
    

    But this is the easy way, don't use ob_clean() and verify your files ! :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集