2013-08-31 40 views

回答

0

這的文字顏色將圍繞主題標籤,跨度元素。

$sampleText = 'This is my sample string #example of what I mean. Here is another #test.'; 
$pattern = '/#[a-zA-Z0-9]*/'; 
$replacement = '<span class="otherColor">$0</span>'; 
$updatedText = preg_replace($pattern, $replacement ,$sampleText); 
print_r($updatedText); 

輸出:

這是我的樣本串<跨度類= 「otherColor」>#例如< /的 我的意思SPAN>。這裏是另一個< span class =「otherColor」>#test </span>。

+0

哦哇!你做得完美 - 驚喜。 – user2527750

+0

你是一個PHP嚮導! – user2527750

相關問題