php trim 不起作用

标签 php javascript ajax xmlhttprequest trim

所以我有一个服务器端 ajax php 文件:

$thing = "\n\ncode\n";
echo(trim($thing, '\n'));

enter image description here

但是当我使用这个 php 文件进行 ajax 调用时,responseText 没有删除换行符!

enter image description here

var xhr7 = new XMLHttpRequest();
xhr7.onreadystatechange = function() {
  if (xhr7.readyState == 4) {
    if (xhr7.status == 200) {
      alert('trying');
      alert(xhr7.responseText);
      chrome.tabs.executeScript(null, {code: xhr7.responseText });
    } else {
      alert("404 server side ajax file DOES NOT EXIST");
    }
  }
};
xhr7.open('POST', 'http://texthmu.com/Devin/HMU%20ext/Post-jsfile-forItsCode.php', true);
xhr7.setRequestHeader("Content-type","application/x-www-form-urlencoded"); //following w3 
xhr7.send(); `

最佳答案

\n 需要用双引号而不是单引号

echo(trim($thing, "\n"));

当值包含在单引号中时,它会被解析为文字。在本例中,使用 \n 而不是您要 trim 的换行符。

关于php trim 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6367291/

相关文章:

javascript - 使用 style.position 定位对象

javascript - 从数据库加载更多状态

javascript - ajax post 成功后淡入淡出

javascript - 使用ajax将html表单以json格式发布到Django

PHP:不同的引号?

javascript - 通过ajax发送DOM

javascript - 同一域的不同选项卡使用单独的本地存储

javascript - 将所有 Backbone 模板放在一个 JS 文件中以便将其放在 CDN 上的最佳方法是什么?

php - 未找到 Symfony 类

php - 从数据库中获取多个字段到数组