how do i add a script code in .php file?

  • Thread starter Thread starter Meesh P
  • Start date Start date
M

Meesh P

Guest
I have a code that start with <script language="javascript"> how and where do I add it in a .php file?
 
PHP is a language and inside of the PHP tags <?php you probably see something like echo "<html>";

to add javascript inside of php use the same echo statements

echo "<script language=\"javascript\">\n";
echo "alert('Hello!!');\n";
echo "</script>\n"

Whatever you echo is what a "browser" would see as HTML markup etc.

I find it is much easier to use " for echo since javascript likes '
also allows you to use variables and the \n .
 
Anywhere you want, just as long as it's not inside php tags, ie:

<?php
...
?>

<script language="javascript">
var i =1;
</script>

<?php
....
?>
 
Back
Top