Page 1 of 1

Very simple problem

Posted: Wed Aug 09, 2006 8:40 am
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]

Posted: Wed Aug 09, 2006 8:42 am
by JayBird

Code: Select all

<?php

$search = $_REQUEST["search"];

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

?>

Posted: Wed Aug 09, 2006 8:45 am
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>