tags:

views:

164

answers:

2

How do I use inverted commas in the echo function in PHP?

echo "<script type="text/javascript">";

doesnt work well.

Thank you!

+1  A: 
echo "<script type=\"text/javascript\">";
serg
+6  A: 

Escape them with backslashes:

echo "<script type=\"text/javascript\">";

Alternatively, you can use a different set of quotes:

echo '<script type="text/javascript">';

Or, HEREDOC syntax:

echo <<<END
<script type="text/javascript">;
END;
Amber
+1 for three goods ways to accomplish this.
Sune Rasmussen
The side effect of using HEREDOCs is that they make everyone hate you for destroying their beautiful code indentation (the "END" cannot be tabbed).
Lotus Notes
On the other hand, they're the easiest to actually keep the content intact with, since you never have to worry about escaping or using the wrong kind of quotes.
Amber