wrapping a variable in a html link tag

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
rabbiz
Forum Newbie
Posts: 2
Joined: Sat Jun 07, 2003 1:47 am

wrapping a variable in a html link tag

Post by rabbiz »

$link1 = "<a href="
$link2 = "> Click Here</a>"
$Website = $link1.$Website.$link2


getting a parse error, unexpected T-VARIABLE on line 2

it doesnt like the ">

I have been racking my brain trying to figure a way around this. anybody got any ideas or suggestions?

thanks
Chris
Trill
Forum Newbie
Posts: 4
Joined: Sat Jun 07, 2003 2:58 am
Location: London, UK

Post by Trill »

Why not do it just by..

$Website = "<a href=\"$Website\">Click here</a>";

seems easier to me.


Trill
rabbiz
Forum Newbie
Posts: 2
Joined: Sat Jun 07, 2003 1:47 am

Post by rabbiz »

lol ty,

I have no idea why I didnt think of that.

thx again
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Much better to do it on one line, but thought I'd give you a heads up as to why that code wasn't working - you need a semicolon at the end of each line, so you should have:

Code: Select all

$link1 = "<a href="; 
$link2 = "> Click Here</a>"; 
$Website = $link1.$Website.$link2;
instead of:

Code: Select all

$link1 = "<a href=" 
$link2 = "> Click Here</a>" 
$Website = $link1.$Website.$link2
Mac
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

twigletmac wrote:Much better to do it on one line, but thought I'd give you a heads up as to why that code wasn't working - you need a semicolon at the end of each line, so you should have:

Code: Select all

$link1 = "<a href="; 
$link2 = "> Click Here</a>"; 
$Website = $link1.$Website.$link2;
And of course the double quotes are missing:

Code: Select all

$link1 = "<a href=""; 
$link2 = ""> Click Here</a>"; 
$Website = $link1.$Website.$link2;
And that was also a problem.
davro
Forum Newbie
Posts: 8
Joined: Fri Nov 01, 2002 6:54 am

Post by davro »

Maybe something like this.

Code: Select all

printf ("<a href="%s" target="%s">%s</a>", $link, $target, $imageortext);
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You really don't need printf() for that - printf() should be used when you need to format the output, not as a substitute for print() or echo().

Mac
Post Reply