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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Feabionsu
Forum Newbie
Posts: 2
Joined: Thu Dec 30, 2010 12:55 pm

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

Post 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>" ?>
Feabionsu
Forum Newbie
Posts: 2
Joined: Thu Dec 30, 2010 12:55 pm

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

Post 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!
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

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

Post 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.
Post Reply