Monday, August 20, 2012

PHP Quotes and HTML

For those who don't know, I was one of you till about a month ago, you can have PHP write double quotes into your html.  You just need a slash in front of each " to keep it part of the string.

$mydiv = "<div class=\"myclass\"></div>";
echo $mydiv;
//<div class="myclass"></div>

This is really handy if you need to pass stuff to a javascript function.

$PassThis = "Passed";
$btn = "<button class='btn' onclick=\"MyFun('$PassThis')\">My Button</button>";

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete