Reputation: 224
I will print the string in PHP, but in a string in there middle of in string double quotes
, single quotes
string also .So I will not get the expected output.
My code Below:
<?php
$str = "Couldn't pay via card";
echo $str . " New "home" away from home when in Bangkok";
echo addslashes($str) . " This is safe in a database query.";
?>
I will useaddslashes() function of PHP to display the string but there some error occurred
output :
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in on line no 5.
How it can be solved?
Upvotes: 0
Views: 2367
Reputation: 3222
You can simly use slashes before your inner quotes like:
echo $str . " New \"home\" away from home when in Bangkok";
or change to single quotes
echo $str . ' New "home" away from home when in Bangkok';
Using single quotes mixed with double quotes does no harm, you can use code like:
"This is " . 'some "sample" text! and it uses \'many\' quotes'
Upvotes: 3