Jump to content

Archived

This topic is now archived and is closed to further replies.

Ph0enix

$_GET stuff

Recommended Posts

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

To test it i used this:

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

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.


[code]
function square_number($number) {
  
  $square= $number * $number;
  return $square;
}
[/code]

How would i call this function, so on the page it would show the result of this function.
Thanks.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
You could do something using a url like:

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

Then your php would be:

[code]<?php

$func = $_GET['function'];

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

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

  return $square;
}

?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.