<?php $text = "theClickClub/sohomortgages/sdfdsf/sdfsdlj%20sdfs&sdfsd=asdfs/index.php?dsjfls=sdfsd&sdfds=342/"; $pos = strlen($text); if(substr($text, $pos-1, 1) == "/") { $text = substr($text,0,$pos-1); } $text = ereg_replace("[^/]*/|\.[^.]*", "", $text)."<br>"; echo $text; ?>