Is is possible to put javascript into a php function? If so could someone please tell me what is wrong with my code? because whenever i put more than one javascript into the php function, my whole functionality will be lost.
<?php
function headerA($title,$css) {
$headContent = <<<HEAD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<title>$title</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="$css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("li").click(function(e) {
e.preventDefault();
$("li").removeClass("selected");
$(this).addClass("selected");
});
});
</script>
</head>
<body>
<div id = "header">
</div>
HEAD;
$headContent .="\n";
return $headContent;
}
?>
$is a key character in PHP, which jQuery uses the same. Escape the characters, or avoid using heredoc if you find it difficult to use