Thread: split an url
View Single Post
Old 2008-07-31, 04:18 PM   #2
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
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.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote