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-]+)\/
Could try something like (?:/[^/]+)+/?$