note 28397 modified in function.dirname by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 19:11:23 +0000 |
| Subject: | note 28397 modified in function.dirname by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142281@lists.php.net to get a copy of this message | ||
dirname can be used to create self referencing web scripts with the following one liner.
<?php
$base_url = str_replace($DOCUMENT_ROOT, "", dirname($PHP_SELF));
?>
Using this method on a file such as:
/home/mysite/public_html/wherever/whatever.php
will return:
/wherever
Now $base_url can be used in your HTML to reference other scripts in the same directory.
Example:
href='<?=$base_url?>/myscript.php'
--was--
dirname can be used to create self referencing web scripts with the following one liner.
$base_url = str_replace($DOCUMENT_ROOT, "", dirname($PHP_SELF));
Using this method on a file such as:
/home/mysite/public_html/wherever/whatever.php
will return:
/wherever
Now $base_url can be used in your HTML to reference other scripts in the same directory.
Example:
href='<?=$base_url?>/myscript.php'
http://php.net/manual/en/function.dirname.php