Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   split an url (http://www.greenguysboard.com/board/showthread.php?t=48243)

Xallow 2008-07-31 03:53 PM

split an url
 
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

cd34 2008-07-31 04:18 PM

If you're trying to remove it from the database, you could do:

Code:

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,

Code:

$path = substr('../../file.extension',3);
If you really wanted to remove those 3 characters, and only those 3 if they were present:

Code:

$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

Code:

$arr = (explode('/','../../file.extension'));
array_shift($arr);
$path = join($arr,'/');

That would always get rid of the first element.

Xallow 2008-08-01 05: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?

cd34 2008-08-01 07:45 PM

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:

Code:

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.


All times are GMT -4. The time now is 06:40 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc