dongmangzong8006 2017-04-23 16:43
浏览 66
已采纳

如何在HTML标记中获取图像URL?

I need to get proper image for each article. Every single image is saved among different HTML tags in different rows in database. So how should I get img URL with PHP code?

 <p><img src="images/akhbar/5/q103.jpg" alt="q103" style="display: block; margin-left: auto; margin-right: auto;" height="315" width="675" /></p>
<p> Who is Sara Bareilles on Sing Off</p>

image urls are saved in introtext row in my database

  • 写回答

2条回答 默认 最新

  • dtrb96410 2017-05-09 09:13
    关注

    thanks for your answers.i could solve my problem with this code.hope help other guys.

    $text = $row["your html text from database row"]; 
    preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $text, $img);
                $pics=$img[1];  
    

    output is ($pics)= ( images/akhbar/5/q103.jpg )

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?