Page 1 of 1

Including PHP variable in <a href> -- please help!

Posted: Thu Dec 30, 2010 1:49 pm
by Feabionsu
Hi there,

I am trying to have a PHP variable in my link, so that my final link would look like this:

http://www.example.com/eformat/variable-goes-here.rtf

I've managed to get http://www.example.com/variable-goes-here using the code below, but I can't seem to insert the "eformat/" and ".rtf" parts. I really don't know PHP very well, so help would be greatly appreciated. Please excuse my beginner level. Thank you!

Code: Select all

<?php $eformat = $post–>post_name; echo "<a href=\"$eformat\">Download this blog post in eFormat (.rtf)</a>" ?>

Re: Including PHP variable in <a href> -- please help!

Posted: Thu Dec 30, 2010 3:42 pm
by Feabionsu
Wow, two solutions have been found on two other forums. :) And here I was trying to figure out even one solution by myself. Just for anyone else with this problem:

Code: Select all

<?php echo "<a href='eformat/{$post->post_name}.rtf'>Download this blog post in eFormat (.rtf)</a>" ?>

Code: Select all

<?php $var = $post->post_name; echo '<a href="eformat/' . $var . '.rtf">Download this blog post in eFormat (.rtf)</a>'; ?>
Resolved!

Re: Including PHP variable in <a href> -- please help!

Posted: Thu Dec 30, 2010 3:45 pm
by danwguy
Without seeing more than just that I would think it would go something like this...

Code: Select all

<?php $eformat = "eformat/" . $post–>post_name . ".rtf"; echo "<a href=\"$eformat\">Download this blog post in eFormat (.rtf)</a>" ?>
I could be wrong, like I said without seeing more that's my best guess.