php 修剪不起作用
所以我有一个服务器端ajax php文件:
$thing = "\n\ncode\n";
echo(trim($thing, '\n'));
但是当我使用这个php文件进行ajax调用时,响应文本没有删除换行符!
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(); `
So I have a server side ajax php file:
$thing = "\n\ncode\n";
echo(trim($thing, '\n'));
But when I use this php file for an ajax call, the responseText does not have newlines removed!
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(); `
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
\n 需要用双引号而不是单引号
当值用单引号括起来时,它会被解析为文字。在这种情况下,
\n
而不是您要修剪的新行字符。\n needs to be in double quotes not single
When a value is in single quotes, it's parsed as a literal. In this case
\n
instead of the new line character you're trying to trim.您需要将
\n
字符放在双引号 ("
) 字符串中。PHP不会在单引号 (
'
) 中解释这些特殊字符>) 分隔字符串。You need to place the
\n
character in a double quoted ("
) string.PHP doesn't interpet these special characters in single quote (
'
) delimited strings.只需使用
参考: http://php.net/manual/en/function.trim.php
以下评论的补充
请注意;
如果您也希望将其删除,那么修剪功能不适合您。
如果你想从字符串中删除所有\n,那么你应该使用
Just use
Ref: http://php.net/manual/en/function.trim.php
Additional for the comments below
Please note that;
If you wish that it be removed too, then trim is not the right function for you.
If you wish to remove ALL \n from a string, then you should use