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? Link to comment https://forums.phpfreaks.com/topic/165298-echo-var2-why-wont-this-work/ 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 Link to comment https://forums.phpfreaks.com/topic/165298-echo-var2-why-wont-this-work/#findComment-871705 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. Link to comment https://forums.phpfreaks.com/topic/165298-echo-var2-why-wont-this-work/#findComment-871741 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 Link to comment https://forums.phpfreaks.com/topic/165298-echo-var2-why-wont-this-work/#findComment-871773 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>"; Link to comment https://forums.phpfreaks.com/topic/165298-echo-var2-why-wont-this-work/#findComment-871902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.