{"id":3580,"date":"2024-05-26T12:07:50","date_gmt":"2024-05-26T03:07:50","guid":{"rendered":"https:\/\/blue-bear.jp\/kb\/?p=3580"},"modified":"2024-05-26T12:09:08","modified_gmt":"2024-05-26T03:09:08","slug":"phpsimplehtmldom%e3%82%92%e5%88%a9%e7%94%a8%e3%81%97%e3%81%a6%e5%af%be%e8%b1%a1url%e3%81%ae%e5%af%be%e8%b1%a1%e3%82%af%e3%83%a9%e3%82%b9%e3%81%ab%e6%89%80%e5%b1%9e%e3%81%99%e3%82%8bimg-url%e3%82%92","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/phpsimplehtmldom%e3%82%92%e5%88%a9%e7%94%a8%e3%81%97%e3%81%a6%e5%af%be%e8%b1%a1url%e3%81%ae%e5%af%be%e8%b1%a1%e3%82%af%e3%83%a9%e3%82%b9%e3%81%ab%e6%89%80%e5%b1%9e%e3%81%99%e3%82%8bimg-url%e3%82%92\/","title":{"rendered":"[PHP]simplehtmldom\u3092\u5229\u7528\u3057\u3066\u5bfe\u8c61URL\u306e\u5bfe\u8c61\u30af\u30e9\u30b9\u306b\u6240\u5c5e\u3059\u308bimg url\u3092\u53d6\u5f97\u3059\u308b"},"content":{"rendered":"\n<p>simplehtmldom\u3092\u5229\u7528\u3057\u3066\u5bfe\u8c61URL\u306e\u5bfe\u8c61\u30af\u30e9\u30b9\u306b\u6240\u5c5e\u3059\u308bimg url\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u5b9f\u73fe\u53ef\u80fd\u3002<\/p>\n\n\n\n<p>URL\u3068\u30af\u30e9\u30b9\u3092\u5165\u529b\u3057\u3066SUBMIT\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001\u5bfe\u8c61URL\u304b\u3089\u753b\u50cf\u30ea\u30b9\u30c8\u3092\u5f15\u3063\u5f35\u3063\u3066\u3053\u308c\u308b<\/p>\n\n\n\n<p>\uff0asimplehtmldom\u306f\u5225\u9014\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304f\u3053\u3068<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html lang=\"ja\">\n&lt;head>\n    &lt;meta charset=\"UTF-8\">\n    &lt;title>\u753b\u50cfURL\u62bd\u51fa\u30d5\u30a9\u30fc\u30e0&lt;\/title>\n&lt;\/head>\n&lt;body>\n    &lt;form action=\"&lt;?php echo htmlspecialchars($_SERVER&#91;\"PHP_SELF\"]); ?>\" method=\"POST\">\n        &lt;label for=\"url\">URL:&lt;\/label>\n        &lt;input type=\"text\" id=\"url\" name=\"url\" required>\n        &lt;br>\n        &lt;label for=\"class\">Class:&lt;\/label>\n        &lt;input type=\"text\" id=\"class\" name=\"class\" required>\n        &lt;br>\n        &lt;button type=\"submit\">\u9001\u4fe1&lt;\/button>\n    &lt;\/form>\n\n    &lt;?php\n\n    \/\/ \u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8aad\u307f\u8fbc\u3080\n    require_once '.\/simplehtmldom\/simple_html_dom.php';\n\n    if ($_SERVER&#91;'REQUEST_METHOD'] === 'POST' &amp;&amp; isset($_POST&#91;'url']) &amp;&amp; isset($_POST&#91;'class'])) {\n        $url = $_POST&#91;'url'];\n        $class = $_POST&#91;'class'];\n\n        \/\/ Get HTML content from the URL\n        $html = file_get_html($url);\n\n        \/\/ Display the retrieved HTML content for debugging\n        echo '&lt;h2>\u53d6\u5f97\u3057\u305fHTML:&lt;\/h2>';\n        echo '&lt;pre>' . htmlspecialchars($html) . '&lt;\/pre>'; \/\/ Display the raw HTML content\n\n        $imageUrls = &#91;];\n\n        foreach($html->find('.'.$class.' img') as $element) {\n            \/\/ Check if the img tag has src attribute\n            if ($element->src &amp;&amp; filter_var($element->src, FILTER_VALIDATE_URL) !== false) {\n                $imageUrls&#91;] = $element->src;\n            }\n\n            \/\/ Check if the img tag has data-src attribute\n            if ($element->getAttribute('data-src') &amp;&amp; filter_var($element->getAttribute('data-src'), FILTER_VALIDATE_URL) !== false) {\n                $imageUrls&#91;] = $element->getAttribute('data-src');\n            }\n        }\n\n        \/\/ Display the results in a simple HTML list\n        echo '&lt;h2>\u62bd\u51fa\u3055\u308c\u305f\u753b\u50cfURL:&lt;\/h2>';\n        if (!empty($imageUrls)) {\n            echo '&lt;ul>';\n            foreach ($imageUrls as $imageUrl) {\n                echo '&lt;li>&lt;a href=\"' . $imageUrl . '\" target=\"_blank\">' . $imageUrl . '&lt;\/a>&lt;\/li>';\n            }\n            echo '&lt;\/ul>';\n        } else {\n            echo '&lt;p>\u753b\u50cfURL\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002&lt;\/p>';\n        }\n    } else {\n        if ($_SERVER&#91;'REQUEST_METHOD'] === 'POST') {\n            http_response_code(400);\n            echo \"\u7121\u52b9\u306a\u30ea\u30af\u30a8\u30b9\u30c8\";\n        }\n    }\n    ?>\n&lt;\/body>\n&lt;\/html><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>simplehtmldom\u3092\u5229\u7528\u3057\u3066\u5bfe\u8c61<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[525,526,63],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3580"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=3580"}],"version-history":[{"count":1,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3580\/revisions"}],"predecessor-version":[{"id":3581,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3580\/revisions\/3581"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=3580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=3580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=3580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}