[Solved] splitting a URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

[Solved] splitting a URL

Post by sulen »

I have a URL string like this

////192.168.1.247/htdocs/20061/DC101_20061/DEN/Homeworks/Incoming/reportee.reportee.reportee

I only want the part after the IP address like this

htdocs/20061/DC101_20061/DEN/Homeworks/Incoming/reportee.reportee.reportee

I tried using a parse_url to break it down but it doesnt recognise IP. So can someone help me with this. Any help will be greatly appreciated. Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it would if that were a qualified URL. That appears to be a Windows networking name.

try something like this

Code: Select all

$path = preg_replace('#^.+?[^/] /#','',$url);
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

Post by sulen »

I used the following code

Code: Select all

$url = "////192.168.1.247/htdocs/20061/DC101_20061/DEN/Homeworks/Incoming/reportee.reportee.reportee";
$path = preg_replace('#^.+?[^/] /#','',$url);
echo $path;
The output it gave was

////192.168.1.247/htdocs/20061/DC101_20061/DEN/Homeworks/Incoming/reportee.reportee.reportee

I guess soemthing is wrong. Thx
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

damned stupid pluses... :evil:

Code: Select all

$path = preg_replace('#^.+?[^/]+/#','',$url);
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

Post by sulen »

Thank you sir it did work indeed.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Gatta love the power of regex. :)
Post Reply