PHP n00b question

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
ph0rz
Forum Newbie
Posts: 4
Joined: Wed Apr 23, 2003 8:57 pm

PHP n00b question

Post by ph0rz »

How do you get like http://www.asdads.com/?force
to get the "force" part into something like
<a href=""force"">adad</a> so whenever I go to http://www.asasa.com/?force
the link would show as <a href="force"> ? Thank you.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Code: Select all

<?php
$link = $_GET['force']; // passing along the variable from the url

echo '<a href="$link">This is a link to: $link</a>';
?>
...i think that's what you're asking. :)
ph0rz
Forum Newbie
Posts: 4
Joined: Wed Apr 23, 2003 8:57 pm

Post by ph0rz »

OMG thank you SO MUCH!
ph0rz
Forum Newbie
Posts: 4
Joined: Wed Apr 23, 2003 8:57 pm

Post by ph0rz »

I have one more question, how do I make like http://www.blah.com/download.php?download.zip to show up as <a href="download.zip">asda</a> ? and also about that code you gave me, when I clicked on the link, it sent me to http://www.blah.com/"$link/" . I am creating a download script for my website. Thanks for your help.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

PHP doesn't parse things in single quotes - you can try:

Code: Select all

echo '<a href="'.$link.'">This is a link to: '.$link.'</a>';
instead of

Code: Select all

echo '<a href="$link">This is a link to: $link</a>';
Mac
ph0rz
Forum Newbie
Posts: 4
Joined: Wed Apr 23, 2003 8:57 pm

Post by ph0rz »

Thanks, got it working.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Hmm yea whoops. :? I should have used double quotes instead of single. So it can be,

Code: Select all

<?php
echo '<a href="'.$link.'">This is a link to: '.$link.'</a>';
?>
or

Code: Select all

<?php
echo "<a href="$link">This is a link to: $link</a>";
?>
I just like the second way more because it's so much less confusing to newbies when reading the code. :)
Post Reply