getting image src in php

后端 未结 4 1544
野趣味
野趣味 2021-01-16 07:17

how to get image source from an img tag using php function.

4条回答
  •  不思量自难忘°
    2021-01-16 07:56

    $path1 = 'http://example.com/index.html';//path of the html page
    $file = file_get_contents($path1);
    $dom = new DOMDocument;
    
    @$dom->loadHTML($file);
    $links = $dom->getElementsByTagName('img');
    foreach ($links as $link)
    {    
        $re = $link->getAttribute('src');
        $a[] = $re;
    }
    

    Output:

    Array
    (
        [0] => demo/banner_31.png
        [1] => demo/my_code.png
    )
    

提交回复
热议问题