Reputation:
I have a very simple question about php. In PHP, can we have script function, javascript or any other script in php section without script tag. Something like this:
<?php
function javascript_or_any_other_script_function() {
}
?>
I am aware that the question is pretty naive (almost silly) but I wanted to see whether php supports this syntax.
Thanks in advance,
Upvotes: 0
Views: 34
Reputation: 271
PHP is in the server, JavaScript is in the browser...
To get JavaScript in client(browser), you need to output it in php...
function javascript_function() {
return 'function foo() {alert("working");}';
}
print('<script>');
print( javascript_function() );
print('</script>')
Upvotes: 1