You can output any type of code that will go into the HTML page using PHP.
Are you trying to get a new page title from the server based on some "on server" processing? If YES, you can make it easier by having a variable defined in JavaScript; I'd suggest an anonymous object or out of GLOBAL scope, and make an AJAX call on a PHP script at the server.
Generating "in page" JavaScript is done all the time.
Although after the code generation is done, there is no longer a connection to the PHP script running on the server. YOU can get very sophisticated and replace JavaScript script tag contents on the fly; even via AJAX calls to a PHP script - as mentioned above.
-
<html>
-
<head>
-
<title><?php echo $page_title?></title>
-
<script type="text/javascript" src="<?php echo getScript()?>"></script>
-
<script type="text/javascript">
-
<?php
-
// Generate a bunch of JavaScript code here...
-
?>
-
</script>
-
</head>
-
<body>
-
-
</body>
-
</html>
-