Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJackie Jen
2,723 PointsWhy a <br /> tag is diplay in a <td> table instead of break new line
Let said i retrieve the data from database and store in $string['description'].
This $string['description'] =
"Description: For the month of june, 2014, including:
i) Review of Management Account for the month of june
ii) Follow-up on Cash Sales for the month of june"
Therefore i want to display the "i)" in next line and "ii)" next line too. so what i do is
$string['description'] = nl2br($string['description'] );
and this is showing me
Description: Description: For the month of june, including:<br /> i) Review of Management Account for the month of june 2014<br /> ii) Follow-up on Cash Sales for the month of june
How to make the <br /> tag axactly perform the new line functions
2 Answers
Jackie Jen
2,723 PointsHi Chris, Gergo
I found the problem why the <br/>
tag not act as new line in html. The reason is because i'm putting htmlsafe function which is protect from XSS attacks through aggressively HTML encoding anything you write between <%= %>
Thanks for helping, appreciate
Chris Shaw
26,676 PointsHi Kenny,
The reason you're seeing <br>
elements is because of the nl2br
function which does the following.
Returns string with
<br />
or<br>
inserted before all newlines (\r\n, \n\r, \n and \r).
So any time it finds a new line character in your string it will automatically replace it with an <br>
element instead.
Jackie Jen
2,723 PointsHi Chris,
yes, the reason i'm using this nl2br
function is to adding the <br />
tag. And this <br />
tag mean new lines in html. But when i display $string['description'] why html does not recognize this <br />
tag as a new line?
Gergő Bogdán
6,664 PointsGergő Bogdán
6,664 PointsCould you share the generated HTML code?