开发者

variable read from text file and passed to smarty shows up like "Home<i>\r</i><i>\n</i>"?

I have a code th开发者_JAVA百科at 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??


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜