Link to home
Start Free TrialLog in
Avatar of SevenAteAnthony
SevenAteAnthonyFlag for United States of America

asked on

Escape Quotes in a PHP Variable

Hi Experts,

Thanks for reading. I'm looking for some advice. In regards to escaping quotes in a variable, is the following okay to do in place of the second code?

$variable = '<div class="box">User\'s Info</div>';

Open in new window


$variable = "<div class=\"box\">User's Info</div>";

Open in new window


Is the first code the best practice? Do you have a better suggestion? Any advice is appreciated.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SevenAteAnthony

ASKER

Thank you for the feedback, DaveBaldwin.
Don't you need to use the dot either way?

<?php

$myvar1 = "linktosomeImage";

echo $myvar1 . " <br />";

$myvar2 = ' &nbsp;&nbsp;&rarr;&nbsp;<a href="'.$myvar1.'" rel="nofollow" title="a little tip here">Right-Click this Link to Save Image</a>';

echo $myvar2;

?>

Open in new window

Thank you.
You're welcome, glad to help.