从PHP中的URL获取人类可读的字符串[关闭]

Given:

$URL = "https://somedomain.com/these-are-words/";

or

$URL = "http://somedomain.com/these-are-words/";

How do I get?:

"these are words"
$url = "https://somedomain.com/these-are-words/";

$path=parse_url($url, PHP_URL_PATH); //extract the path


$words=str_replace('-',' ',trim($path,'/')); //replace the hyphen with spaces and remove the /'s


echo $words; //these are words

It really depends on the variety of input strings you have, but something like this should work (though you may need to tweak it to suit your needs):

https?:\/\/\w+\.\w+\/([\w-]+)\/

Demo

Could try something like (?:/[^/]+)+/?$