views:

26

answers:

2

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??

+1  A: 

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.

Oren
Tried, but don't understand it. I added require('libs/plugins/outputfilter.trimwhitespace.php'); and tried $test = smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $sidebar); but don't know what $_script_blocks means? Is there a easier way to remove this stuff. I tried strip_tags($sidebar) as well, but that shows up blank!
ganjan
A: 

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.

animuson