Anna Harris wrote:I always use echo "<script> function(); </script>";
It doesn't work in the way you think it does. You don't even need to have an "echo"- just placing
<script> function(); </script> outside <?php ?> tags does the same as what with "echo" does. Particularly, it 'prints' that fragment as a text in the HTML content, and your browser interprets the generated HTML and there is a Javascript snippet calling your function - that's now something like calling-JS-from-PHP.
If calling to a Javascript method in a separate file is all what you need, simply 'import' that Javascript file using
<script src> in your <head> block, and then you can call its functions anywhere in the body as you always do.