Jump to content

[SOLVED] Help with echo with ' and "


Darkmatter5

Recommended Posts

I'm trying to echo this to my page:

 

<form><input type='button' onclick='parent.location="res_addgame.php"' value='Add game'><input type='button' onclick='parent.location="res_addmovie.php"' value='Add movie'></form>

 

But the following code only prints out:

 

echo "<form><input type='button' onclick='parent.location='res_addgame.php'' value='Add game'><input type='button' onclick='parent.location='res_addmovie.php'' value='Add movie'></form>";

 

<form><input type='button' onclick='parent.location='res_addgame.php'' value='Add game'><input type='button' onclick='parent.location='res_addmovie.php'' value='Add movie'></form>

 

How do I echo out a double quote or output an equivalent?

Link to comment
https://forums.phpfreaks.com/topic/141949-solved-help-with-echo-with-and/
Share on other sites

You need to escape some characters in php;

 

e.g.

<?php
$foo = "To use a double quote here you need to "escape it" a single quote is 'fine'";
$bar = 'If you wrap with 'single quote' it works the "other way round"';

 

for you code use;

<?php
$foo = '<form><input type="button" onclick="parent.location='res_addgame.php'" value="Add game"><input type="button" onclick="parent.location='res_addmovie.php'" value="Add movie"></form>';

EDIT, the bbcode gets rid of ym back slashes;

 

eg1

<?php

$foo = "To use a double quote here you need to \"escape it\" a single quote is 'fine'";

$bar = 'If you wrap with \'single quote\' it works the "other way round"';

 

eg2

<?php

$foo = '<form><input type="button" onclick="parent.location=\'res_addgame.php\'" value="Add game"><input type="button" onclick="parent.location=\'res_addmovie.php\'" value="Add movie"></form>';

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.