我有以下代碼:如何使這個表達式否定
$content = eregi_replace('!([a-zA-Z0-9]+)', '<a href="http://www.example.com/link/\\1">\\1</a>', $content);
完美的作品,但我希望它忽略重複的單詞。
例如爲:
!堆疊! 堆棧! !溢出! !溢出
他應該只得到第一個,並忽略重複,因此不會形成鏈接。
我有以下代碼:如何使這個表達式否定
$content = eregi_replace('!([a-zA-Z0-9]+)', '<a href="http://www.example.com/link/\\1">\\1</a>', $content);
完美的作品,但我希望它忽略重複的單詞。
例如爲:
!堆疊! 堆棧! !溢出! !溢出
他應該只得到第一個,並忽略重複,因此不會形成鏈接。
使用preg_replace()
和它的limit
參數
$content = '!stack! stack! !overflow! !overflow';
$newcontent = preg_replace('#!([a-zA-Z0-9]+)#','<a href="http://www.example.com/link/\\1">\\1</a>',$content,1);
哦,謝謝... :) – user2707203
這隻會替換一次。我認爲OP希望一次替換每個不同的單詞。不只是一個字。 – Qtax
@Qtax確切.... – user2707203
重複必須被刪除? –
請詳細解釋你想要得到的東西。 – urzeit
你應該使用['preg_replace()'](http://uk3.php.net/preg_replace)而不是['eregi_replace()'](http://uk3.php.net/eregi_replace) [不贊成](http://uk3.php.net/eregi_replace)(雖然這不是你沒有做你想做的理由) – SmokeyPHP