2014-11-16 127 views
0

我需要從不同的URL獲取一個人的名字。如何從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/

不同,但它並沒有限制到這些變化(只有人的姓名保持格式firstname-姓氏)

我需要把名稱在這樣一個變量中的人:

$ personName =「Firstname Lastname」;

我該怎麼做? P.S. :可以使用純PHP或一些Wordpress功能完成。

+0

以使用**爆炸的URL)的最後部分(**,然後用** str_replace()函數**替換 - 與空間'。您可能還想檢查** ucfirst()**函數。 –

回答

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

希望幫助:)