Skip to content

Instantly share code, notes, and snippets.

@nczz
Created February 20, 2020 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nczz/0c06f005c87a0cbada1a0111066e9f30 to your computer and use it in GitHub Desktop.
Save nczz/0c06f005c87a0cbada1a0111066e9f30 to your computer and use it in GitHub Desktop.
抽圖片出來處理的方法 HTTP -> HTTPS
<?php
//抽圖片出來處理 HTTP -> HTTPS
@$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$image->removeAttribute('alt');
$image->removeAttribute('width');
$image->removeAttribute('height');
$image->removeAttribute('title');
$image->removeAttribute('original');
$image->removeAttribute('style');
if (strpos($image->getAttribute('src'), 'http') === false) {
$url_path = explode('//', $image->getAttribute('src'));
$image->setAttribute('src', 'https://' . $url_path[1]);
}
}
$content = $dom->saveHTML($dom->documentElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment