How i can insert html scripts with php?

991 views php
-1

I want to try insert script element with php, in my index.php

<?php
    echo "Welcome to my index.php"
?>

this is the content of my script .js

alert("Hello there!");

answered question

1 Answer

12

You can use php echo for it:

<?php
    echo "Welcome to my index.php"; 
    echo '<script>alert("Hello there!");</script>';
?>

another example:

<?php
    echo "Welcome to my index.php"; 
    echo '<script>alert("Hello there!");</script>';
    echo '<script>
        document.body.innerHTML += "<p>Inserted from php</p>"
    </script>';
?>

posted this

Have an answer?

JD

Please login first before posting an answer.