从文本文件读取并传递给 smarty 的变量显示为“Home\r\n”?
我有一个看起来像这样的代码。
$language = "eng";
$append = "_sidebar.txt";
$read_text_file = "languages\\$language$append";
$sidebar = file($read_text_file);
$smarty->assign("sidebar_link",$sidebar);
为什么 smarty 中的所有变量都是这样的:
Smarty_Variable Object (3)
->value = Array (13)
0 => "XX<i>\r</i><i>\n</i>"
1 => "XX<i>\r</i><i>\n</i>"
2 => "XX<i>\r</i><i>\n</i>"
3 => "XX<i>\r</i><i>\n</i>"
4 => "XX<i>\r</i><i>\n</i>"
XX 代表单个单词。 \r\n 来自哪里?
I have a code that look like this.
$language = "eng";
$append = "_sidebar.txt";
$read_text_file = "languages\\$language$append";
$sidebar = file($read_text_file);
$smarty->assign("sidebar_link",$sidebar);
Why does all variables in smarty all look like this:
Smarty_Variable Object (3)
->value = Array (13)
0 => "XX<i>\r</i><i>\n</i>"
1 => "XX<i>\r</i><i>\n</i>"
2 => "XX<i>\r</i><i>\n</i>"
3 => "XX<i>\r</i><i>\n</i>"
4 => "XX<i>\r</i><i>\n</i>"
with the XX representing single words. Where does \r\n come from??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
\r\n
只是一个 Windows 换行符(即按下“Enter”键),位于从文件中读取的行末尾。您可以删除文件中的所有换行符,也可以按照 上的说明进行操作此论坛帖子 应用条带(或变体)过滤器,让 Smarty 为您过滤掉控制字符。
The
\r\n
is simply a windows linefeed (i.e. an "enter" key press) at the end of the lines that are being read from your file.You could either remove all line breaks in the file, or you could follow the instructions on this forum post to apply a strip (or a variation) filter to make Smarty filter out the control characters for you.
“\n”是一个表示新行或换行符的字符,在 Windows 系统中通常前面有一个“\r”(因为我猜他们喜欢为每个换行符添加额外的字符)。如果没有换行符,所有文本都会像“XXXXXXXXXX”一样流动在一起,因为无法分辨每行在哪里断开。
A "\n" is a character that indicates a new line, or line break, and is usually preceded by a "\r" in Windows systems (because they like adding extra characters for every line break I guess). Without the line breaks, all the text would flow together like "XXXXXXXXXX" because there would be no way to tell where each line breaks off.