Jump to content


Photo

$_GET stuff


  • Please log in to reply
3 replies to this topic

#1 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 25 June 2006 - 12:51 PM

Hi, im still learning PHP and iv just started to learn about the $_GET thing.

To test it i used this:

<?php
print $_GET["test"];
?>

So then if i typed in my address bar

[a href=\"http://localhost/stuff/page.php?test=hello\" target=\"_blank\"]http://localhost/stuff/page.php?test=hello[/a]

Then i would get a page that displays "hello".

But i want to know how do i call a function.

So if i used this code for example.


function square_number($number) {
  
  $square= $number * $number;
  return $square;
}

How would i call this function, so on the page it would show the result of this function.
Thanks.
[url=http://www.slimphoenix.com][/url]

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 June 2006 - 12:54 PM

Did you read the fine manual on [a href=\"http://www.php.net/manual/en/functions.returning-values.php\" target=\"_blank\"]using the return[/a] statement in functions? The first example tells you how to do that.

Ken

#3 Ph0enix

Ph0enix
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 25 June 2006 - 01:10 PM

Ok thanks.
But erm isnt there somthing i could write in the address bar to veiw the result of the function like..

[a href=\"http://localhost/stuff/page.php?test=function(sqare_number)\" target=\"_blank\"]http://localhost/stuff/page.php?test=function(sqare_number)[/a]
(i know this is wrong)

Cause on Postnuke you have to do something like this to display a function

[url=http://www.slimphoenix.com][/url]

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 25 June 2006 - 02:33 PM

You could do something using a url like:

www.whatever.com/number=2&function=square

Then your php would be:

<?php

$func = $_GET['function'];

echo call_user_func($func, $_GET['number']);

function square_number($number) {
  $square= $number * $number;

  return $square;
}

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users