$string = 'www.web.com/dir_name/t5721.html';$string = preg_replace("#(.*)/(.*)/(.*)#i","Your Dir Is : $2", $string); echo $string;