如何从URL,PHP,Wordpress获取名称


How to get a name from URL, PHP, Wordpress

我需要从不同的URL中获取一个人的名字。

例子:

网址可能因 http://www.example.com/John-Smith/而异

到 http://www.example.com/some-other-info/hellen-leroy/

到 www.example.com/some/other/info/nick-waller/

但不限于这些变体(只有此人的名字保持名字-姓氏格式)

我需要将人名放在这样的变量中:

$personName ="名字姓氏";

我该怎么做?附言:可以使用纯PHP或某些Wordpress函数来完成。

$temp = explode('/', $_SERVER['REQUEST_URI']);
$temp = explode('-', $temp[count($temp)-1];
$firstName = $temp[0];
$lastName = $temp[1];

希望对:)有所帮助