php用正則表達式去除子符串中由數字、字母、符號組成的不規則子串的方法

<?php
$str=<<<start
<a href="http://" target="_blank" stat="123fdsfdsfds">aaa</a>
start;
$pattern="((stat\=\".+?)\")";
$replace="";
$result=preg_replace($pattern,$replace,$str);
echo $result;
?>

上面應該屬於非貪婪匹配的方法吧,個人也是學習php的時候,在網上看到的說法:

運行代碼得到的結果是:


<a href="http://" target="_blank" >aaa</a>

大家可以試下!

參考網站:http://cn.php.net/preg_replace/

學習php的朋友,一起討論哈。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章