extract image src from text?

前端 未结 3 1535
不知归路
不知归路 2020-12-20 02:10

I have a variable $content that contains some text and images in this form (unknown amount of images):

    text text text text 

        
3条回答
  •  眼角桃花
    2020-12-20 02:29

        $dom = new domDocument;
        $dom->loadHTML($html);
        $dom->preserveWhiteSpace = false;
        $imgs  = $dom->getElementsByTagName("img");
        $links = array();
        for($i = 0; $i < $imgs->length; $i++) {
           $links[] = $imgs->item($i)->getAttribute("src");
        }
    

提交回复
热议问题