如何用其他数字替换数字,例如
$str = "www.mysite.com/campagin_id=12345";
我想用另一个号码6789替换12345
所以输出将是
www.mysite.com/campagin_id=6789
答案 0 :(得分:2)
str_replace('12345', '6789', $str);
答案 1 :(得分:0)
$str = "www.mysite.com/campagin_id=12345";
preg_replace("/id=(\d+)$/", "6789", $str);
<强>输出:强>
www.mysite.com/campagin_id=6789
答案 2 :(得分:0)
免费解决方案
<?php
$str='www.mysite.com/campagin_id=12345';
$yournum = 6789;
echo $var = explode('=',$str)[0]."=".$yournum;
<强> OUTPUT :
强>
www.mysite.com/campagin_id=6789