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 trialManea Alexandru
9,174 PointsIn php function, i hawe <h4> tag, and i want add in this tag a echo
Hello, in this function, i want add echo $item["title"] in "<h4> </h>" tags, is posibile this ?
function get_item_html($id,$item) { echo $item["genre"]; $output = "<ul><a href='#'><video src='" . $item["video"] . " ' alt='" . $item["title"] . "' />" . "<h4> how can i add a echo here ? </h>" . "</a></ul>";
2 Answers
Corey Cramer
9,453 PointsThere are two easy ways to accomplish this. The first is by concatenation like you were doing for the rest of the string:
<?php
function get_item_html($id,$item)
{
echo $item["genre"];
$output = "<ul><a href='#'><video src='" . $item["video"] . " ' alt='" . $item["title"] . "' />" . "<h4>" . $item["title"]. "</h4>" . "</a></ul>";
}
?>
The alternative is to just use the variables in the quotes which I think is cleaner.
<?php
function get_item_html($id,$item)
{
echo $item["genre"];
$output = "<ul><a href='#'><video src='{$item['video']}'> alt='{$item['title']}'/><h4>{$item['title']}</h4></a></ul> ";
}
?>
After that, all you need to do is keep in mind that you aren't returning the output variable in your function currently.
Edit: Added closing brackets
Purvi Agrawal
7,960 PointsTry this
<h4> <?php echo $item["title"] ; ?> </h4>
This is called escaping php in html. Whenever u want to add any php between html tags, use <?php ?>. Let me know if this works !
Manea Alexandru
9,174 PointsHello, thank you for answer, but me I want add first time the html tag in php function, and after php in this tag.
Manea Alexandru
9,174 PointsManea Alexandru
9,174 PointsHello, thank you for answer, i tried like this, but does not display the html tag, just display the video.
Corey Cramer
9,453 PointsCorey Cramer
9,453 PointsIt is an error with your HTML and the way you have things like russian nesting dolls but at this point the PHP is functioning properly.
Try like this..
Now what you have is an unordered list with a list item and a link that includes your title which is closed, after that the video you're trying to load, then closing the list item and the unordered list.
It becomes this:
versus this:
Manea Alexandru
9,174 PointsManea Alexandru
9,174 PointsYes, now work fine, thank you very much!