treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Wrap $ in Tag?

  • Anyone know how I'd wrap $likes in a span tag? If it's even possible.

    $likes = likeThis($post_id);

    Sorry if I make no sense at all, I'm still trying to wrap my head around PHP.

    Thanks in advance.
  • echo '<span>' . $likes . '</span>';


    No question is too basic when you're just starting out
  • By the way, what @TT_Mark did there is called concatenation. You can concatenate a string, such as "Hello World" to a variable or another string using a period/full stop, and you can do it as many times as you want.
  • @TT_Mark Thanks for the help guys. That's why I love this forum.

    I'm trying to modify a plugin called Like This.

    My PHP looks like this at the moment.

    function printLikes($post_id) {
    $likes = likeThis($post_id);

    $who = 'Love it? ';

    if(isset($_COOKIE["like_" . $post_id])) {
    print '<a href="#" class="likeThis done" id="like-'.$post_id.'">'.$who. '<span>'.$likes.' loves</span></a>';
    return;
    } //if
    print '<a href="#" class="likeThis" id="like-'.$post_id.'">'.$who. '<span>'. $likes.' loves</span></a>';
    } //printLikes
    I've wrapped both $likes in a span tag. The span tag is present before I like the item, but when I "like" the item the span tag disappears, this is the one with the "done" class.

    Hope that makes sense, thanks.
  • Seems it been changed by the js.

    At the end of function reloadLikes(who)

    $j("#" + who).text(text);


    That might be the problem.