正则表达试,获取指定id ,class 对应标签的内容

只匹配第一个
<a href="javascript:void(0);" id="js_name">禾葡兰</a>

   public function get_time(){
        $regex="/<a (.*?) id=\"js_name\">(.*?)<\/a>/is";  
        $return = file_get_contents('https://mp.weixin.qq.com/s/ZX5j3V1W3L6UykSVyfoASg');
        preg_match($regex, $return, $matches);
        print_r($matches);
    }
匹配全部
$regex="/<div class=\"tideTable\"(.*?)>(.*?)<\/div>/ism";  
preg_match_all($regex, $return, $matches)  
   print_r($matches);  
//抓取jS里的值
public function get_time(){
        $regex='/var ct="(\d+)"/';    //获取ct="",里面的数字
        $str =  'var ct="1531288854"*1';
        preg_match($regex, $str, $matches);
        print_r($matches);
    }

猜你喜欢

转载自blog.csdn.net/wbj16116/article/details/81084044
今日推荐