php怎么替换大于5位数的数字为:
比如:内容有123 , 1234 ,12345,但是只替换大于5位数的数字,也就是替换12345为
<img src="tar.php?=12345" width="709" height="29" />
比如:内容有123 , 1234 ,12345,但是只替换大于5位数的数字,也就是替换12345为
<img src="tar.php?=12345" width="709" height="29" />
解决方案 »
- 每5个循环输出怎么写啊?
- 大哥大姐们帮我解释下着句代码?????非常感谢!!!!!
- 使用imagettftext函数时需要安装Freetype的问题
- require或者include引入文件的时候能够传递参数吗
- apache和PHP关联不起来
- 求救:错误:Parse error: syntax error, unexpected T_VARIABLE in c:\AppServ\www\test2.php on line 8
- 看内容
- php5+apache2+mysql4+phpmysqladmin 问题
- 请问大家如何用php将mysql里面的数据倒出到excel,或者Access里面,急~
- 想交换一些书!有兴趣请进!!!
- 下载数据问题。
- mysql_affected_rows ()运用错误的问题
echo preg_replace('/\d{5,}/', 'haha', $t);<img src="tar.php?=haha" width="709" height="29" />
自动替换内容大于5位数的数字为
<img src="tar.php?=数字" width="709" height="29" />
$string = preg_replace("/^(.*)(12345)(.*)$/si","\\1<img src=\"tar\.php\?=\\2\">\\3",$string);
echo $string;exit;
继续求最佳答案谢谢回复者:
自动替换内容大于5位数的数字为
<img src="tar.php?=数字" width="709" height="29" />
就用:
<?php
$string='1234电信移动12345afsdf342342sdf ';
$str =preg_replace('/^(.*)(\d{5,})(.*)$/','\\1<img src="tar.php?=\\2" width="709" height="29" />\\3',$string);
?>
如果你字符串里面有多个大于5位的数字字符串,都想替换的话
就用:
<?php
preg_match_all('/\d{5,}/',$string,$matches);
foreach($matches as $single)
$answer=str_replace($single,"<img src='tar.php?=$single' width='709' height='29' />",$string);
?>
该是这个
<?php
$string='1234电信移动12345afsdf342342sdf';
preg_match_all('/\d{5,}/',$string,$matches);
foreach($matches[0] as $single)
{
$string=str_replace($single,"<img src='tar.php?=$single' width='709' height='29' />",$string);
}
echo $string;
?>这回对了,测试过的
比如字符为“$string='1234电信移动12345afsdf342342sdf123456789'; ”
<?php
$string='1234电信移动12345afsdf12345342342sfdss12345vxcdf ';
$str =preg_replace('/(\d{5,})/','<img src="tar.php?=\\1" width="29" height="29" />',$string);
echo $str.'<br>';
?>
这下肯定对~