Escape Characters Not Working?

So I’m a noob and just started learning how to code a few days ago.

I’m faced with the following problem:

I’m learning about escape characters, specifically: /n, /r , and /t

I made the following statement:

$heading = “Date\nName\nPayment”;
echo $heading;

and got the following output:

Date Name Payment

But, shouldn’t it look more like this:

Date
Name
Payment

I’m writing with Zend and using a MAMP. Thanks for the help.

Those aren’t escape characters. They tell php to do something

/n = unix new line
/r = windows new line
/t = tab character

/n and /r wont’ do anything visible on screen, but if you look at the source code through the browser, you’ll see what it does. in your example, $heading = “Date\nName\nPayment”; would print dateNamePayment on the screen, but if you look at the code, you’d see

Date
Name
Payment

They’re more used to control how content is displayed on the source side, makes it really easy to troubleshoot scripts if you can made sense of what’s being shown to you. hard has hell to look at 1 large block of code rather than codes that’s organized on multiple lines.

If you wanted it to display on your screen on the web-page as new line:

[php]
$heading = “Date\nName\nPayment”;
echo nl2br($heading);
[/php]

The nl2br function turns newline into html
tags.

Sponsor our Newsletter | Privacy Policy | Terms of Service