我想知道如何使用preg_replace將php字符串中的一些文本替換爲不同的值。用PHP替換一些不同值的文本preg_replace
例如:
- http://www.mysite.com/?uid=123456
- http://www.mysite.com/?uid=123456
- http://www.mysite.com/?uid=123456
我想這樣的結果:
- http://www.mysite.com/?uid=456789
- http://www.mysite.com/?uid=789456
- http://www.mysite.com/?uid=159753
我已經使用這個代碼:
$string = 'http://www.mysite.com/?uid=123456<br/>
http://www.mysite.com/?uid=123456<br/>
http://www.mysite.com/?uid=123456';
$string = preg_replace(array("~123456~", "~123456~", "~123456~"), array("456789","789456","159753"), $string);
echo $string;
,但它給了我這樣的結果:
- http://www.mysite.com/?uid=456789
- http://www.mysite.com/?uid=456789
- http://www.mysite.com/?uid=456789
任何幫助嗎?
謝謝!
你是如何在你想要的結果獲得UID號?他們看起來隨機? –