Regex & PHP - isolate src attribute from img tag

前端 未结 10 1452
眼角桃花
眼角桃花 2020-11-28 08:55

With PHP, how can I isolate the contents of the src attribute from $foo? The end result I\'m looking for would give me just \"http://example.com/img/image.jpg\"



        
10条回答
  •  盖世英雄少女心
    2020-11-28 09:43

    I got this code:

    $dom = new DOMDocument();
    $dom->loadHTML($img);
    echo $dom->getElementsByTagName('img')->item(0)->getAttribute('src');
    

    Assuming there is only one img :P

提交回复
热议问题