![]() ![]() ![]() ![]() |
|||||
|
|||||
樓主 tien ![]()
![]() |
如果要截取顯示 https://XXX.php?id=38 裡的第一張照片,當background-image 這樣可以嗎? <?php $background_url = "https://XXX.php?id=38"; ?> <div style="background-image: url(<?php echo $background_url ;?>)"> 但由於https://XXX.php?id=38不是圖片,所以顯示不出來,請問我還要再增加什麼? |
1樓 |
google 一下
https://stackoverflow.com/questions/15895773/scraping-all-images-from-a-website-using-domdocument $html = file_get_contents('http://www.google.com/'); $dom = new domDocument; $dom->loadHTML($html); $dom->preserveWhiteSpace = false; $images = $dom->getElementsByTagName('img'); foreach ($images as $image) { echo $image->getAttribute('src'); }
本篇文章回覆於2021-08-16 09:28
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
2樓
作者回應
tien ![]() |
照片還是顯示不出來?
本篇文章回覆於2021-08-16 10:37
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
3樓 |
images 抓到什麼。沒有有抓到你要的。
本篇文章回覆於2021-08-16 10:51
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
4樓
作者回應
tien ![]() |
沒有抓到images,一樣是都空白的
本篇文章回覆於2021-08-16 11:42
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
5樓 |
https://XXX.php?id=38 內容是什麼?
本篇文章回覆於2021-08-16 12:26
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
6樓
作者回應
tien ![]() |
只有一張圖片,我爬文有看到這個
https://www.ostraining.com/blog/coding/extract-image-php/ <?php $html = file_get_contents('http://www.website.any'); preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i',$html, $matches ); echo '<img src="http://www.website.any' . $matches[ 1 ][ 0 ] . '" />'; ?> 怎麼把echo '<img src="http://www.website.any' . $matches[ 1 ][ 0 ] . '" />'; img src改為background-image 放在這裡面呢? style="background-image: url(" ")"
本篇文章回覆於2021-08-16 15:19
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
7樓 |
$matches[ 1 ][ 0 ]就是圖片的相對位置。把 domain 跟 圖片位置的字串相加 放進 background-image: url
本篇文章回覆於2021-08-17 09:24
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
8樓
作者回應
tien ![]() |
如果我把 echo '<img src="http://www.website.any' . $matches[ 1 ][ 0 ] . '" />'; 這一段加入 background-image: url裡面
顯示會變成 background-image: url(" <img src="http://www.website.any/images/abp1.png">") 圖片還是會顯示不出來
本篇文章回覆於2021-08-17 10:33
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
9樓
最有價值解答
asakous ![]() |
$image = '<img class="foo bar test" title="test image" src=\'http://example.com/img/image.jpg\' alt="test image" width="100" height="100" />';
$array = array(); preg_match( "/src='([^\"]*)'/i", $image, $array ) ; print_r( $array[1] ) ; #http://example.com/img/image.jpg
本篇文章回覆於2021-08-17 12:04
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
回覆 |
如要回應,請先登入. |