user674073
user674073

Reputation: 159

php in body -- missing something obvious

My PHP is not PHPing, so made simple test... must be missing something obvious.

<html>
<head>
</head>
<body>
 <?php echo '<script language=\"javascript\">confirm("Do you see this?")</script>;'; ?>
</body>
</html>

In code body, I get: confirm("Do you see this?");'; ?>


When I "View Source", I see:

<html> <head> </head> <body> <?php echo '<script language=\"javascript\">confirm("Do you see this?")</script>;'; ?> </body> </html>

Upvotes: 0

Views: 1308

Answers (3)

knittl
knittl

Reputation: 265918

what extension has your file? is a webserver running? how are you calling your php script?

make sure it has a .php extension, the webserver is running, the file resides under the webroot directory and you call it via http://localhosti/path/to/file.php

also make sure you don't escape quotation marks when not needed, echo '<script type="text/javascript">…</script>'; should do the job

Upvotes: 2

Ashley
Ashley

Reputation: 5957

Take out the \ from the double quotes and the extra semi colon

<html>
<head>
</head>
<body>
 <?php echo '<script language="javascript">confirm("Do you see this?")</script>'; ?>
</body>
</html>

Upvotes: 0

mvds
mvds

Reputation: 47114

You should remove the backslashes from the \"javascript\".

<?php echo '<script language="javascript">confirm("Do you see this?")</script>;'; ?>

In PHP you can put strings in single ' or double " quotes. This is quite hard to explain (and/or understand) in a few lines, so here's a few valid ways to write down a string containing quotes:

echo 'This has "double quotes"...';
echo 'This has \'single quotes\'...';
echo "This has \"double quotes\"...";
echo "This has 'single quotes'...";

There are many more subtleties to this, but this should get you started.

Upvotes: 0

Related Questions