Last active
April 17, 2024 17:08
-
-
Save hayatbiralem/081c2c89e7a7cb524e1d47c69d74283b to your computer and use it in GitHub Desktop.
WP All Export get the image urls from the post content
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 | |
function reboot_remove_image_dimensions($str){ | |
$re = '/-\d+x\d+\./m'; | |
return preg_replace($re, '.', $str); | |
} | |
function reboot_get_content_images($id){ | |
$p = get_post($id); | |
$doc = new DOMDocument(); | |
libxml_use_internal_errors(true); | |
$doc->loadHTML( $p->post_content ); | |
$xpath = new DOMXPath($doc); | |
$imgs = $xpath->query("//img"); | |
$urls = []; | |
for ($i=0; $i < $imgs->length; $i++) { | |
$img = $imgs->item($i); | |
$src = $img->getAttribute("src"); | |
if(strpos($src, 'phardon.com') !== false) { | |
$urls[] = $src; | |
} | |
} | |
$concat_urls = implode('|', $urls); | |
return reboot_remove_image_dimensions($concat_urls); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment