а нужно ли?
$a = '<span style="font-size:18px"><span style="color:#FF0000">Apollo 11 was the spaceflight that <span style="font-family:courier new,courier,monospace">landed the first humans</span></span><span style="font-family:courier new,courier,monospace">, Americans </span>Neil Armstrong and Buzz Aldrin, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.</span>';
$dom = new DOMDocument;
$dom->loadHTML($a);
echo '<pre>';
function recurse($a, $i){
var_dump("$i -> " . $a->nodeName );
if( $a->nodeName != '#text' )
foreach( $a->childNodes as $t )
recurse($t, $i+1);
}
foreach( $dom->documentElement->childNodes as $i )
recurse($i, 0);
$one = "/folder1/2/f3/folder4/five/";
$two = "/folder1/2/f3/folder4/five";
preg_match("/.*\/([^\/.]+)/", $one, $one_matches);
echo $one_matches[1]; //five
preg_match("/.*\/([^\/.]+)/", $two, $two_matches);
echo $two_matches[1]; //five
function getLastPath($url) {
preg_match("/[^\?.]*\/([^\/\?.]+)/", $url, $res);
return $res[1];
}
echo getLastPath("/f1/correct/?a=folder3/f4/"); //correct
echo getLastPath("/folder1/2/correct/"); //correct
echo getLastPath("/folder1/2/f3/correct"); //correct
echo basename($url), PHP_EOL;
// если адрес содержит get-параметры или якоря
echo basename(parse_url($url)['path']), PHP_EOL;
ideone.com/fMIXvt