echo an anchor and href with PHP variables (1 Viewer)

ajetrumpet

Banned
Local time
Yesterday, 20:30
Joined
Jun 22, 2007
Messages
5,638
i am echoing a table on a PHP page, and a typical line looks like this:
PHP:
	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

AWF VIP
Local time
Today, 02:30
Joined
Jan 22, 2010
Messages
26,374
i am echoing a table on a PHP page, and a typical line looks like this:
PHP:
    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!
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:

PHP:
    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

Banned
Local time
Yesterday, 20:30
Joined
Jun 22, 2007
Messages
5,638
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:

PHP:
    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

AWF VIP
Local time
Today, 02:30
Joined
Jan 22, 2010
Messages
26,374
I trusted you would have cracked it Adam. PHP is fun isn't it:D
 

ajetrumpet

Banned
Local time
Yesterday, 20:30
Joined
Jun 22, 2007
Messages
5,638
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

AWF VIP
Local time
Today, 02:30
Joined
Jan 22, 2010
Messages
26,374
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.
 

Users who are viewing this thread

Top Bottom