Created
February 20, 2020 13:38
-
-
Save nczz/0c06f005c87a0cbada1a0111066e9f30 to your computer and use it in GitHub Desktop.
抽圖片出來處理的方法 HTTP -> HTTPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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