preg_replace を使用して、php 文字列内のテキストを別の値に置き換える方法を知りたいです。
例えば :
- 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
助けはありますか?
ありがとう !