Reputation: 8882
I have a string like this:
<form action='php/zoneNotifUnsub.php' id='zoneNotifUnsub' method='POST'>
<?php
echo $var;
?>
</form>
I want to echo it out with PHP, and have it look exactly as above.
I started with this:
echo '<form action='php/zoneNotifUnsub.php' id='zoneNotifUnsub' method='POST'>
<?php
echo $var;
?>
</form>';
But the additional single quotes inside are causing me problems. How can I have the exact verbatim output of my string print (so that no variables are parsed and no code is run)?
Upvotes: 0
Views: 118
Reputation: 198
Using double quotes could be an option in this case:
echo "<form action='php/zoneNotifUnsub.php' id='zoneNotifUnsub' method='POST'>
<?php
echo $var;
?>
</form>";
Upvotes: 1
Reputation: 7250
You can also use double quotes for the things you want to echo.
So: '<form action="php/zoneNotifUnsub.php" id="zoneNotifUnsub" method="POST">';
and so on.
Upvotes: 2
Reputation: 38961
Normal Escaping would look like this:
echo '<form action=\'php/zoneNotifUnsub.php\' id=\'zoneNotifUnsub\' method=\'POST\'>
<?php
echo $var;
?>
</form>';
Escaping every one of the '
with a backslash. To recap how strings work look in the manual page
You could also go with the HEREDOC Syntax
that would look a little bit nicer:
echo <<<OUT
<form action='php/zoneNotifUnsub.php' id='zoneNotifUnsub' method='POST'>
<?php
echo $var;
?>
</form>
OUT;
Upvotes: 3
Reputation: 82559
Try escaping them
echo '<form action=\'php/zoneNotifUnsub.php\' id=\'zoneNotifUnsub\' method=\'POST\'>
<?php
echo $var;
?>
</form>';
Upvotes: 1