+ 4
How can i code with both php and javascript
php
2 Antworten
+ 7
It's fine to do as Kaimi writes and should work just fine; this is just additional info.
I don't think PHP's place is clear enough here, so note, this code is perfectly acceptable:
<html>
<head><title>My page</title></head>
<body>
<script>
alert("prewritten content");
<?php echo(" alert('injected from php'); "); ?>
</script>
</body>
</html>
My point is, PHP takes a fully-functional web page, scans for PHP tags, and then does stuff exactly there.
It sends anything else (that isn't PHP) without changing it.
I prefer this pattern so that PHP-generated content ends up in the right places -- like <body> or <head> -- without making the client browser guess.