interesting problem of trying to get string within hyperlink

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
josboogz
Forum Newbie
Posts: 12
Joined: Thu Feb 06, 2003 5:05 am

interesting problem of trying to get string within hyperlink

Post by josboogz »

Hi all,

i am trying to print out a table from a database table and trying to make one of the fields a link to another webpage.

What i am trying to do is to make the last data in the row a link:

print "\t<td><font face=verdana size=2/><a href='http://www.cs.nott.ac.uk/Modules/0203/$var.html'>Full spec</a></font></td>\n";

The problem is i would like to enter a string variable as part of the hyperlink address. So in the example above i want to get $var to be recognised as part of the address. I have tried to concatentate like

print "\t<td><font face=verdana size=2/><a href='http://www.cs.nott.ac.uk/Modules/0203/' <? echo $var;?>.html'>Full spec</a></font></td>\n";

But i get a problem with the "" as it doesnt recognise the embedded PHP tags as it is already within PHP tags.

Can anyone help?????

Thank you for ur time.

Jos
net7
Forum Commoner
Posts: 31
Joined: Wed Mar 12, 2003 1:27 pm

Post by net7 »

One thing that might work would be this :

Code: Select all

$url="http://www.site.com/path/&#123;$var&#125;.html";

print "\t <td> <font face=verdana size=2/> <a href=&#123;$url&#125;>Full spec</a></font></td>\n";
Hope it works, goodluck.
josboogz
Forum Newbie
Posts: 12
Joined: Thu Feb 06, 2003 5:05 am

Post by josboogz »

Hey thanks very much net7 it works a treat!!!

Thanks again for the help!! much appreciated.
redJag
Forum Newbie
Posts: 18
Joined: Fri Jan 31, 2003 12:17 am

Re: interesting problem of trying to get string within hyper

Post by redJag »

josboogz wrote: print "\t<td><font face=verdana size=2/><a href='http://www.cs.nott.ac.uk/Modules/0203/' <? echo $var;?>.html'>Full spec</a></font></td>\n";
This would have worked fine if you changed it slightly:

Code: Select all

print "\t<td><font face=verdana size=2/><a href='http://www.cs.nott.ac.uk/Modules/0203/'". $var ."html'>Full spec</a></font></td>\n";
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you want to have code formatting (ie. tabs and spaces) maybe you should consider using heredoc format:
http://www.php.net/manual/en/language.t ... ax.heredoc

Mac
Post Reply