-2

I wrote this:

<!DOCTYPE HMTL>
<html>
    <head>
    </head>
    <body>
        <?php
            $javascript = echo '<script type = "text/javascript">',
            'prompt("Hello");', '</script>';;
        ?>
    </body>
</html>

And it says:

Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\xampp\htdocs\h.php on line 7

marcelovca90
  • 2,673
  • 3
  • 27
  • 34

2 Answers2

0
 <!DOCTYPE HMTL>
<html>
<head>
</head>
<body>
<?php
echo $javascript = '<script type = "text/javascript">prompt("Hello");</script>';
?>
</body>
</html>
Ankit vadariya
  • 1,253
  • 13
  • 14
  • Thank you, it works – Jared Herrera Dec 23 '16 at 17:15
  • `= "string" ?>` == `` **since PHP v5.4** – Mihailo Dec 23 '16 at 17:23
  • @Mihailo That's supported way before 5.4, probably since the very beginning of PHP, except the `short_open_tag` option can disable it before 5.4 as `=` was recognized as a special short tags case as it's easy to distinguish from XML's ``: http://php.net/manual/en/language.basic-syntax.phptags.php – Ultimater Dec 23 '16 at 17:27
  • @Ultimater yup I know. I didn't feel like it was necessary to write the details. But sure now we have the details as well. – Mihailo Dec 23 '16 at 17:42
0

You can simply echo the script using echo (without even using the variable)

<?php
echo '<script type = "text/javascript">prompt("Hello");</script>';
?>

Or Using variable

<?php
echo $javascript = '<script type = "text/javascript">prompt("Hello");</script>';
?>

Or using shorthand

<?='<script type = "text/javascript">prompt("Hello");</script>'?>
jophab
  • 5,356
  • 14
  • 41
  • 60