Page 1 of 1

interesting problem of trying to get string within hyperlink

Posted: Thu Mar 13, 2003 1:15 pm
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

Posted: Thu Mar 13, 2003 1:27 pm
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.

Posted: Thu Mar 13, 2003 1:31 pm
by josboogz
Hey thanks very much net7 it works a treat!!!

Thanks again for the help!! much appreciated.

Re: interesting problem of trying to get string within hyper

Posted: Thu Mar 13, 2003 2:11 pm
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";

Posted: Fri Mar 14, 2003 2:04 am
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