- //方法一代碼如下
- $str = '<a href="http://www.49028c.com" target="_blank" name="doc3_p"><img src="" onload="setImgSize(this,170,170);"></a>';
- preg_match_all ('|^<a href="(.*)".*|U',$str,$out, PREG_PATTERN_ORDER);
- print_r($out);
- //方法二代碼如下
- preg_match_all('/href=['"]+(.*)['"]+/',$str,$matches);
- var_dump($matches[1]);
- //方法三代碼如下
- //(?<=<as*)href=[^ '">]+
- //方法四代碼如下
- preg_match("/<as*href="(.*?)"[^>]*>.*?</a>/is", $str, $aMatch);
- print_r($aMatch[1]);
- //方法五代碼如下
- preg_match_all('/href=('|"|s)*([^'">s]+)/i',$str,$match);
- print_r($match);
- preg_match_all('/src=('|"|s)*([^'">s]+)/i',$str,$match);
- print_r($match);
上面這正則得到url的地址都是用了php正則表達試來實現的,只是方法有一點不同了.
新聞熱點
疑難解答