Very simple problem

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
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Very simple problem

Post by impulse() »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


After reading a few chapters of a PHP book I'm trying to create a HTML document that passes the value of a text box to a PHP file as a variable. The passing of the variable runs smooth it's just outputting the variable as part of a hyperlink to click.
It basically goes like this once the variable $search has been passed to the following PHP page:

Code: Select all

<?php

$search = $_REQUEST["search"];

<a href="http://www.google.co.uk/search?q=$search"> Click to search </a>

?>
I get the feeling at this point that you will be saying "You can't put HTML inside PHP". So what's the solutions to creating hyperlinks in PHP?

Regards,


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

<?php

$search = $_REQUEST["search"];

echo '<a href="http://www.google.co.uk/search?q='.$search.'"> Click to search </a>';

?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Or doing it the way PHP hybrids with HTML:

Code: Select all

<?php

$search = $_REQUEST["search"];

?>
<a href="http://www.google.co.uk/search?q=<?php echo $search; ?>"> Click to search </a>
Post Reply