How to get the last 2 directories from a URL using PHP ???

  • barry
  • Graduate
  • Graduate
  • User avatar
  • Posts: 115
  • Loc: scotland

Post 3+ Months Ago

Hi all. Can any one tell me how to get the last 2 directories from a URL using php

just now i am using

(btw im not allowed to post to external links so i cant show the actual link to the site

Code: [ Select ]
preg_match('/(http:\/\/)(.*).html/', "basepathtodirectory using http path/2010/12/end-of-week-3-update-patch-143-closed.html", $link);

$path_parts = pathinfo($link[0]);
  1. preg_match('/(http:\/\/)(.*).html/', "basepathtodirectory using http path/2010/12/end-of-week-3-update-patch-143-closed.html", $link);
  2. $path_parts = pathinfo($link[0]);



and i get the full url.. i just want $url to equal the path to the last 2 directories

so $path_parts will be just

/2010/12/end-of-week-3-update-patch-143-closed.html

Any help would be great!!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6241
  • Loc: Seattle, WA

Post 3+ Months Ago

You should be able to modify the regex in this SO answer to include the file as well:

http://stackoverflow.com/questions/3837 ... 90#3837690

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 107 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.