View Full Version : echo an anchor and href with PHP variables


ajetrumpet
03-04-2010, 03:09 PM
i am echoing a table on a PHP page, and a typical line looks like this: echo '<tr>';
echo '<td align="center"><a href="files/"' . $log[$i] .
substr($log[$i], 0, strpos($log[$i], "-") - 2) . '".zip">' . $log[$i] . '</a></td>';
echo '</tr>';this sample code is pulling the value $log[$i] which is equal to: financialpack - 26mb

my hyperlink echoes fine, but the address comes out as: www.mydomain/files/. the PHP variables aren't being read. I have also tried to put the vars inside the double quotes with the HREF, to no avail. not sure what to try next. can someone with some PHP knowledge give me a push here? thanks!

vbaInet
03-04-2010, 05:34 PM
i am echoing a table on a PHP page, and a typical line looks like this: echo '<tr>';
echo '<td align="center"><a href="files/"' . $log[$i] .
substr($log[$i], 0, strpos($log[$i], "-") - 2) . '".zip">' . $log[$i] . '</a></td>';
echo '</tr>';this sample code is pulling the value $log[$i] which is equal to: financialpack - 26mb

my hyperlink echoes fine, but the address comes out as: www.mydomain/files/ (http://www.mydomain/files/). the PHP variables aren't being read. I have also tried to put the vars inside the double quotes with the HREF, to no avail. not sure what to try next. can someone with some PHP knowledge give me a push here? thanks!This would seem your concatenation in conjunction with the quotes is incorrect and hence, not reaching the first variable. I'm too rusty in PHP, forgotten everything but try this:

echo '<tr>';
echo '<td align="center"><a href="files/' . $log[$i] . substr($log[$i], 0, strpos($log[$i], "-") - 2) . '.zip">' . $log[$i] . '</a></td>';
echo '</tr>';

ajetrumpet
03-04-2010, 08:36 PM
This would seem your concatenation in conjunction with the quotes is incorrect and hence, not reaching the first variable. I'm too rusty in PHP, forgotten everything but try this:

echo '<tr>';
echo '<td align="center"><a href="files/' . $log[$i] . substr($log[$i], 0, strpos($log[$i], "-") - 2) . '.zip">' . $log[$i] . '</a></td>';
echo '</tr>';

thanks bud. I got it figured out right before you posted this i think. your solution is right on though.

vbaInet
03-05-2010, 01:17 AM
I trusted you would have cracked it Adam. PHP is fun isn't it:D

ajetrumpet
03-07-2010, 11:28 AM
I trusted you would have cracked it Adam. PHP is fun isn't it:D
the one thing I commonly forget is the article I read on the net where the author said you CAN include vars inside double quotes in PHP with it arguing with you. but the single quotes are a no-no. who came up with these stupid rules anyway!?

I was reading an article on how to pass GET variables from page to page throughout a nav session

vbaInet
03-07-2010, 11:33 AM
Yes that was what I remembered when I saw the line. It's a bit of a silly one. Maybe it's got something to do with portability on the net since there are so many parsers and protocols.