search

Home  >  Q&A  >  body text

php - Find regular loop matching

 <dd class="iqiyi"><a href="http://www.iqiyi.com/v_19rrbc8ups.html" target="_blank">20170408$http://www.iqiyi.com/v_19rrbc8ups.html</a></dd><dd class="iqiyi"><a href="http://www.iqiyi.com/v_19rrbd47ic.html" target="_blank">20170407$http://www.iqiyi.com/v_19rrbd47ic.html</a></dd><dd class="iqiyi"><a href="http://www.iqiyi.com/v_19rrnfp1nk.html" target="_blank">20170407$http://www.iqiyi.com/v_19rrnfp1nk.html</a></dd><dd class="iqiyi"><a href="http://www.iqiyi.com/v_19rrbcsn9g.html" target="_blank">20170406$http://www.iqiyi.com/v_19rrbcsn9g.html</a></dd>

I want to loop through the value in the a tag, such as:
20170408$http://www.iqiyi.com/v_19rrbc...
20170407$http://www.iqiyi.com /v_19rrbd...

How should

be written?

高洛峰高洛峰2827 days ago515

reply all(4)I'll reply

  • 世界只因有你

    世界只因有你2017-05-16 13:18:57

    preg_match_all('/(\d{8}\$[^<]+)/', $subject, $result, PREG_PATTERN_ORDER);
    for ($i = 0; $i < count($result[0]); $i++) {
        # Matched text = $result[0][$i];
    }

    reply
    0
  • 怪我咯

    怪我咯2017-05-16 13:18:57

    It feels so cumbersome to use regular expressions to do this. Can you directly search for tags like this:

    var a = document.querySelectorAll('a');
            a.forEach((item)=>{
                console.log(item.innerText);
            })

    reply
    0
  • 怪我咯

    怪我咯2017-05-16 13:18:57

    $string = '<dd class="iqiyi"><a href="http://www.iqiyi.com/v_19rrbc8ups.html" target="_blank">20170408$http://www.iqiyi.com/v_19rrbc8ups.html</a></dd><dd class="iqiyi"><a href="http://www.iqiyi.com/v_19rrbd47ic.html" target="_blank">20170407$http://www.iqiyi.com/v_19rrbd47ic.html</a></dd><dd class="iqiyi"><a href="http://www.iqiyi.com/v_19rrnfp1nk.html" target="_blank">20170407$http://www.iqiyi.com/v_19rrnfp1nk.html</a></dd><dd class="iqiyi"><a href="http://www.iqiyi.com/v_19rrbcsn9g.html" target="_blank">20170406$http://www.iqiyi.com/v_19rrbcsn9g.html</a></dd>';
    
    $ret = preg_match_all('#(<a.*?>)(.*?)(</a>)#', $string, $matchs);
    
    var_dump($matchs);

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:18:57

    $pattern = '/<a[^>]*>([^<]*)<\/a>/';
    $temp = preg_match_all($pattern, $html, $match);

    reply
    0
  • Cancelreply