Page 1 of 1

Grabbing variable from a function

Posted: Mon Aug 29, 2005 1:10 pm
by MajorJerk
Hello, I'm using this function

Code: Select all

function current_dir()
{
$path = dirname($_SERVER[PHP_SELF]);
$position = strrpos($path,'/') + 1;
print substr($path,$position);
}
substr($path,$position);
To grab the part of the current url that I need. The print line prints out the part I want just fine.

My question is, how can I use that extracted part as a variable to use in a sql queiry?
I tried $nm = substr($path,$position); but $nm is empty. :?:

Thanks. :D

Posted: Mon Aug 29, 2005 1:15 pm
by feyd
neither $path nor $position are sent outside the function. You need to return the substring result.

Code: Select all

function current_dir()
{
  $path = dirname($_SERVER['PHP_SELF']);
  $position = strrpos($path,'/') + 1;
  return substr($path,$position);
}

$dir = current_dir();

If you want to get the current directory on the server's paths: getcwd() may help.

Posted: Mon Aug 29, 2005 2:29 pm
by MajorJerk
Perfect! tyvm. :D