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 trialsamsor ithnin
3,175 Points\n not working
i dont know why \n not working. its not make new line.i am confuse.
below is the code
<?php
class render { public static function displayRecipe($recipe){
$output = "";
$output .= $recipe->getTitle() . " by " . $recipe->getSource();
$output .= "\n";
$output .= implode(",",$recipe->getTags());
foreach($recipe->getIngredients() as $ing){
$output .= $ing["amount"] . $ing["measure"] . $ing["item"];
$output .= "\n";
}
$output .= implode("\n",$recipe->getInstructions());
$output .= "\n";
$output .= $recipe->getYields();
return $output;
} }
?>
1 Answer
Konrad Traczyk
22,287 PointsHello Samson, when you're opening your php script in a browser its by default considered as HTML document.
You can get desired effect in 2 ways.
- Set header to text/plain, at the begining of your script like that:
<?php
header('Content-type: text/plain');
- Or use nl2br function to insert brs into your output.
Hope it helps
samsor ithnin
3,175 PointsHai konrad.both method given by you are working great.but i choose number 2. thank you.
Marie Urbina
7,168 PointsBeautiful! Thanks. That 2nd method seems a little complicated; I didn't try it. The first's just fine!
Erdem Meral
25,022 PointsErdem Meral
25,022 PointsCan you please share your code. Are you sure \n is inside the double quotes?