Re: Relative Url
| From: | Red Wingate | Date: | Fri, 02 Apr 2004 14:18:03 +0000 |
| Subject: | Re: Relative Url | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-182126@lists.php.net to get a copy of this message | ||
Ok found his one on some old libs of mine, guess this should work but i am not sure :
<?php
function find_relativ_path( $origin , $target ){
$append = '';
$string = '';
$origin = explode('/',$origin);
$target = explode('/',$target);
unset($origin[(count($origin)-1)]);
unset($target[(count($target)-1)]);
for ( $i = 0 ; TRUE ; $i++ ){
if ( !isset($target[$i]) AND !isset($origin[$i]) )
break;
if ( strlen($string) == 0 AND $origin[$i] == $target[$i] ){;
continue;
}else if ( isset($target[$i]) AND $origin[$i] != $target[$i] ){
$append .= $target[$i].'/';
if ( isset($origin[$i]) ){
$string .= '../';
}
}else{
$string .= '../';
}
}
return $string.$append;} ?> Use this with $pollFunctions_path and $foo_path Red Wingate wrote:
Hi chris, Haven't much time now but maybe you can find a way with those ideas: in pollFunctions.php do : $pollFunctions_path = str_replace( basename ( _FILE_ ) , '' , _FILE_ ); in foo.php do : $foo_path = str_replace( basename ( _FILE_ ) , '' , _FILE_ ); Now you just have to compute the diff between $foo_path and $pollFunctions_path. Hope this helps :-) -- red Chris Thomas wrote:What im trying to do is this. I working on creating a poll script, and right now it consists of 3 main files:poll.php - Which does the server-side processing pollFunctions.php - Which draws the poll and does some client side stuff poll.css - stylesheetThese files reside in the /poll directory (for now) pollFunctions.php is included in the file that wants the poll, which may reside in any folder. So what im trying to figure out is the relative url of where the pollfunctions.php file resides. -- Now that i think about it i could just include the stylesheet from the calling file (ie index.php) I probally should have thought of this a little more before i posted...oh well Chris "Chris Shiflett" <shiflett@php.net> wrote in message news:20040401165403.50351.qmail@web14310.mail.yahoo.com...--- Chris Thomas <cwthomas@connectmail.carleton.ca> wrote:Is there anyway that i can get a url relative to my server for a script that is being run??$relative_url = '/'; That's a relative URL to your document root. What are you wanting, exactly? Chris ===== Chris Shiflett - http://shiflett.org/ PHP Security - O'ReillyComing Fall 2004HTTP Developer's Handbook - Samshttp://httphandbook.org/PHP Community Sitehttp://phpcommunity.org/