View Full Version : split an url
Xallow
2008-07-31, 04:53 PM
hi guys and gals
I think I am getting tired, I have an url in a database called the following:
../../file.extention
I need to change that url to:
../file.extention
I can't for the life of me figure it... I know I am stupid... I need to split, but I cant get it to work
All help appreciated
Xallow
If you're trying to remove it from the database, you could do:
update tablename set path=replace(path,'../../','../');
That would replace ../../../ with ../../ which may not be what you intend. You could set a condition on the update to match only those records that you want to fix.
If you are trying to remove it from some data, and you knew it was just the first three characters,
$path = substr('../../file.extension',3);
If you really wanted to remove those 3 characters, and only those 3 if they were present:
$path = preg_replace('/^..\//','','../../file.extension');
that way, if the string started with /asdf/file.extension, it wouldn't be affected
Another possibility is parse_url, but, I am not sure how it would react.
If you knew that you wanted to pull the first 'section' at the first /, you could do something like
$arr = (explode('/','../../file.extension'));
array_shift($arr);
$path = join($arr,'/');
That would always get rid of the first element.
Xallow
2008-08-01, 06:43 PM
Thanks, that worked, I have another question though.
Is it not possible to get access to a folder on my server from my website? I created a folder on the server where my domains are hosted to use the files from that folder on all my sites, but when I link to those files I get nothing. Do I need to set some permission thingies or something?
Depends on the server config. There are so many possible answers and configurations that you might need to check with your host. They could be restricting opens, you might be served from two different fileservers, so, while the path may look identical, you could be on two totally different paths, or many other possibilities.
You might do something like:
echo getcwd();
on each of your sites so that you can get the 'absolute' path. Though this might show you a chrooted path and not give you the true result. Your host should be able to help.
vBulletin® v3.8.1, Copyright ©2000-2026, Jelsoft Enterprises Ltd.