Jump to content

$_GET stuff


Ph0enix

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.
Link to comment
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
Link to comment
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
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.