Page 1 of 1

Dynamic Relative Paths

Posted: Tue Feb 01, 2005 3:49 pm
by neophyte
I've been working on a script today to calculate dynamic relative paths.

Code: Select all

//Calculate correct relative paths
if  (substr_count( $_SERVERї'REQUEST_URI'], '/') != 1)
{
$relative_path ='';
for($x=0;$x < substr_count( $_SERVER&#1111;'REQUEST_URI'], '/') -1; $x++)
&#123;
$relative_path .= '../';
&#125;
$link_path = $relative_path;
&#125;
Does anybody know of a better way to do this than what I've done? Is there a built in function I don't know about? Do you think this will work to attach $link_path to the front of my links? It seems to be working in my tests. What do you all think?

Posted: Tue Feb 01, 2005 6:30 pm
by feyd
could use str_repeat along with the call to substr_count..

Posted: Tue Feb 01, 2005 8:25 pm
by neophyte
You mean something like....

Code: Select all

$link_path = str_repeat ('../' ,(substr_count( $_SERVER&#1111;'REQUEST_URI'], '/') -1));
That's cool Feyd!
8)