Reputation: 337
I need a function to return a relative path of the file , every where i run it. for example this is my code in "loc.php" :
<?
echo whereiam();
?>
outputs in these directories should be:
public_html/loc.php : /
public_html/folder1/folder2/loc.php : ../../
Is there any built-in function in php for this use?
Upvotes: 0
Views: 102
Reputation: 157917
This is apparently wrong idea of doing something else.
There is no point in getting ../../
-style paths out of current location. You can (and should) use an absolute one.
Upvotes: 0
Reputation: 4209
The closest thing you're going to get is:
<?php
echo $_SERVER["SCRIPT_FILENAME"];
?>
EDIT: As for the second part of your script, I would probably do something like count the number of '/'s -1 in $_SERVER["SCRIPT_NAME"] and echo out that many ../'s? As far as I know there is no function that does something like this out of the box.
Upvotes: 0