php trim无法正常工作

Dev*_*ode 0 javascript php ajax trim xmlhttprequest

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

$thing = "\n\ncode\n";
echo(trim($thing, '\n'));
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

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

在此输入图像描述

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(); `
Run Code Online (Sandbox Code Playgroud)

Ben*_*owe 10

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

echo(trim($thing, "\n"));
Run Code Online (Sandbox Code Playgroud)

当值是单引号时,它被解析为文字.在这种情况下,\n而不是你想要修剪的新行字符.