By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,216 Members | 1,032 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,216 IT Pros & Developers. It's quick & easy.

how can I assign a variable value to a href

100+
P: 123
Hi all,
I have some results which I need to link with their original files.
they are stored in variable $str
how can I give a href a variable name ??
code is below
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $str = "MS/2008-09/003/0112.ps ";
  3. print('<a href = "/$str" >Info</a>');
  4. ?>
  5.  
how can I assign a variable to a href ???
Sep 30 '08 #1
Share this Question
Share on Google+
4 Replies


Markus
Expert 5K+
P: 6,050
Like so (you could use concatenation, but doing it in a value always confuses me with the quotes)

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $str = "MS/2008-09/003/0112.ps ";
  3. print("<a href = \"/{$str}\" >Info</a>");
  4. ?>
Notice I have escaped the quotes within quotes with backslashes.
Sep 30 '08 #2

pbmods
Expert 5K+
P: 5,821
Heya, AJD.

If you used echo instead of print, you could do this:

Expand|Select|Wrap|Line Numbers
  1. echo '<a href="', $str, '">Info</a>';
  2.  
But you might want to consider doing this, instead:

Expand|Select|Wrap|Line Numbers
  1. echo '<a href="', htmlentities($str), '">Info</a>';
  2.  
Sep 30 '08 #3

100+
P: 123
Hi All,
Thanks for the solutions.
Oct 1 '08 #4

Markus
Expert 5K+
P: 6,050
Hi All,
Thanks for the solutions.
Welcome. Glad we could help!
Oct 1 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.