一些PHP正则,常用到的



3、PHP替换url为链接

      $pattern= '@((http|ftp|https)://)?(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\&%_\./-~-]*)?@';
      $message= preg_replace_callback($pattern, "url_match", $message);

       输入:匹配正则地址:sina.com.cn/s/blog_797c9c9f0101atzj.html
       最终效果:匹配正则地址:<a href="http://sina.com.cn/s/blog_797c9c9f0101atzj.html" target="_blank">sina.com.cn/s/blog_797c9c9f0101atzj.html</a>



2、删除连续空行或者单独空行

$cc = preg_replace('/($\s*$)|(^\s*^)/m', '', $cc);


1、将1234567890转换成1,234,567,890 每3位用逗号隔开的形式

<?php 

$num = "1234567890.11";  

$num = preg_replace('/(?<=[0-9])(?=(?:[0-9]{3})+(?![0-9]))/', ',', $num); 

echo $num; 

?>

300*300
  • 没有相关文章
  • 没有评论
 文章首页关于迷茫时代关于我写意人生
版权所有:迷茫时代 All rights reserved   
执行时间:0.00466 秒