Aro2220 Posted July 9, 2009 Share Posted July 9, 2009 Hi, I am trying to get the following script to run but it doesn't put the values of the variables into the echo... echo '<a href="$var1">$var2</a>'; result is an html link called $var2 that links to $var1 if i echo "$var1"; or echo "$var2"; i get the value of the variable displaying correctly. Why is this happening? How do I do what I want to do? Quote Link to comment Share on other sites More sharing options...
Aro2220 Posted July 9, 2009 Author Share Posted July 9, 2009 never mind, i figured it out. echo "<a href='$var1'>$var2</a>"; works as I intended it to. I'm still not entirely sure about when ' and " should be used, but oh well! Thanks Quote Link to comment Share on other sites More sharing options...
p2grace Posted July 9, 2009 Share Posted July 9, 2009 Single quotes do not parse variables, they are used when the output doesn't need to contain php variables. Double quotes do parse php variables. Another alternative is heredoc. Quote Link to comment Share on other sites More sharing options...
aximbigfan Posted July 9, 2009 Share Posted July 9, 2009 Single quotes are simple strings, and will to be parsed by PHP. Double quotes will be parsed. $var = 'no vars here'; echo 'The var is $var'; // Will output: The var is $var echo "The var is $var"; // Will output: The var is no vars here Quote Link to comment Share on other sites More sharing options...
Octave91 Posted July 9, 2009 Share Posted July 9, 2009 try this buddy echo "<a href='" . $var1 . "'>$var2</a>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.