常用正则表达式整理(持续更新中)

常用正则表达式整理(持续更新中)

1、替换商品详情中图片的高和宽

1 $str = '<p><img src="/uploads/20190308/FuwOxhHmoE8JP1rA_kg2JDTMFsGf.jpg" alt="" width="500" height="481" />
2 <img src="/uploads/20190308/FjGfFmn4_9XskCQ4rwSJ6EayDHfA.jpg" alt="" width="500" height="481" />
3 <img src="/uploads/20190308/Fvf3IzrGs-_0ak8hztGjlWc4IR1T.png" alt="" width="500" height="441" /></p>';
4 echo $str;
5 $str = preg_replace('/\bwidth="(\d+)"/', 'width="100%"', $str);
6 $str = preg_replace('/\bheight="(\d+)"/', 'height="100%"', $str);
7 echo $str;die;

2、验证手机号字段

1     protected function checkMobile($str)
2     {
3         return (preg_match("/^1[0-9]{1}[0-9]{9}$/",$str)) ? true : false;
4     }

3、验证金额,价格字段

1     protected function checkPrice($str)
2     {
3         return (preg_match("/^\d{1,8}(\.\d{1,2})?$/",$str)) ? true : false;
4     }

 

posted @ 2019-03-11 10:50  落日长烟  阅读(198)  评论(0编辑  收藏  举报