我想用帶有鏈接的文本替換文本中的名稱。用鏈接替換文本中的名稱
$text = "text with names in it (John) and Jacob.";
$namesArray("John", "John Plummer", "Jacob", etc...);
$LinksArray("<a href='/john_plom'>%s</a>", "<a href='/john_plom'>%s</a>", "<a href='/jacob_d'>%s</a>", etc..);
//%s shout stay the the same as the input of the $text.
但如果有必要,可以改變數組。
我現在使用2個數組str_replace。像這樣$text = str_replace($namesArray, $linksArray, $text);
,但替換喊叫工作的名稱與「點」或「)」或類似的東西在結束或開始。我怎樣才能讓替換工作在這樣的文本上。
輸出喊是"text with names in it (<a.....>John</a>) and <a ....>Jacob</a>."
那麼你想在雅各布中刪除一個點嗎? – serg 2010-06-21 21:13:41
你的'$ namesArray'看起來像什麼? – jigfox 2010-06-21 21:15:16
沒有輸出提示是「帶有名稱的文本(約翰)和Jacob」。 該數組看起來像$ namesArray(「John」,「John Plummer」,「Jacob」等); 鏈接數組是$ LinksArray(「%s」等)。 %s留言保持與$文本的輸入相同。 但如果有必要可以改變數組。 –
Remi
2010-06-21 21:30:10