Grabbing the href attribute of an A element

前端 未结 10 2395
悲&欢浪女
悲&欢浪女 2020-11-21 05:06

Trying to find the links on a page.

my regex is:

/]*href=(\\\"\\\'??)([^\\\"\\\' >]*?)[^>]*>(.*)<\\/a>/
10条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 05:50

    I agree with Gordon, you MUST use an HTML parser to parse HTML. But if you really want a regex you can try this one :

    /^

    This matches at the begining of the string, followed by any number of any char (non greedy) .*? then href= followed by the link surrounded by either " or '

    $str = 'what?';
    preg_match('/^

    Output:

    array(3) {
      [0]=>
      string(37) "what?"
      [1]=>
      string(1) """
      [2]=>
      string(4) "that"
    }
    

提交回复
热议问题