Re: escape \n

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You can also just send out the correct Header for plain text. But your
HTMl will not be interpreted then.. So this makes only sense if you
actually want plain text as the output format.

header("Content-type: text/plain; charset=utf8");
echo "foo\nbar";


Regards

2010/4/23 Nick Balestra <nick@xxxxxxxxxxxx>:
> Thanks everybody!
>
> On Apr 23, 2010, at 10:05 AM, Ashley Sheridan wrote:
>
>> On Fri, 2010-04-23 at 09:51 +0200, Nick Balestra wrote:
>>>
>>> Hello guys i am trying to figure out what is worng with thoose special escaped character, like \n \t \r ...
>>>
>>> As i cannot make them working. The browser doesn't display them, but doesn't eithr crate a new line, or else.
>>> I am using them fro example like this:
>>>
>>> print: "this shoudl be on a line \nwhile this on a new line";
>>>
>>> I've searched google and saw man people struggling with this, but apparently not a clear answer to why....maybe is a stupid beginner question, but i would just like to know.  (Personally i solved for the moment by printing out <br> or <pre>, but i would like to understand this.
>>>
>>> Cheers, Nick
>>
>> By default, PHP sends out HTML headers. Browsers ignore extraneous white-space characters, and also new lines, carriage returns and tabs, converting them all to a single space character.
>>
>> If you view the source in your browser, you'll see the newlines, but in regular display, your text is treated as HTML.
>>
>> There is a function in PHP called nl2br, which accepts a string and returns the same one with all the newlines replaced with <br> automatically, which might be easier to use if your content is in a string. Otherwise, the only way to get new lines on your actual page is to either manually use <br> tags, put the text inside a <pre> block, or use CSS to preserve the white-space.
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux