{"id":5743,"date":"2012-11-12T22:25:15","date_gmt":"2012-11-12T13:25:15","guid":{"rendered":"http:\/\/nanoappli.com\/blog\/?p=5743"},"modified":"2012-11-13T22:44:03","modified_gmt":"2012-11-13T13:44:03","slug":"phpfile_get_contenst%e3%81%a7%e8%a4%87%e6%95%b0%e3%82%b5%e3%82%a4%e3%83%88%e3%81%aehtml%e3%82%92%e9%9d%9e%e5%90%8c%e6%9c%9f%e3%81%a7%e9%ab%98%e9%80%9f%e3%81%ab%e5%8f%96%e5%be%97%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"http:\/\/nanoappli.com\/blog\/archives\/5743","title":{"rendered":"[PHP]file_get_contenst()\u3067\u8907\u6570\u30b5\u30a4\u30c8\u306ehtml\u3092\u975e\u540c\u671f\u30fb\u9ad8\u901f\u306b\u53d6\u5f97\u3059\u308b"},"content":{"rendered":"<p>\nPHP\u3067\u306f\u3001file_get_contenst()\u95a2\u6570\u306bURL\u3092\u6307\u5b9a\u3059\u308b\u4e8b\u3067\u3001\u4ed6\u306e\u30b5\u30a4\u30c8\u306ehtml\u30c6\u30ad\u30b9\u30c8\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<br \/>\n1\u3064\u306e\u30b5\u30a4\u30c8\u3060\u3051\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306f\u3053\u308c\u3067\u3088\u3044\u306e\u3067\u3059\u304c\u3001\u5927\u91cf\u306e\u30b5\u30a4\u30c8\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u3001<br \/>\n1\u30b5\u30a4\u30c8\u3064\u3065\u9806\u756a\u306b\u95a2\u6570\u3092\u547c\u3093\u3067\u3044\u305f\u3089\u975e\u5e38\u306b\u6642\u9593\u304c\u639b\u304b\u308a\u307e\u3059\u3002<br \/>\n<br \/>\n<br \/>\n\u3053\u306e\u3088\u3046\u306a\u5834\u5408\u306fcURL\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u6709\u308bcurl_multi_getcontent()\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u8907\u6570\u30b5\u30a4\u30c8\u306e\u60c5\u5831\u3092\u975e\u540c\u671f\u3067\u540c\u6642\u306b\u53d6\u5f97\u51fa\u6765\u307e\u3059\u3002<br \/>\n<br \/>\n<br \/>\n\u3067\u3059\u304c\u3001curl_multi_getcontent()\u306f\u3001\u30ea\u30bd\u30fc\u30b9\u306e\u78ba\u4fdd\uff65\u958b\u653e\u51e6\u7406\u304c\u5fc5\u8981\u3067\u3001\u6271\u3044\u304c\u3061\u3087\u3063\u3068\u7169\u96d1\u3067\u3059\u3002<br \/>\n\u3053\u306e\u70ba\u3001\u4eca\u56de\u306ffile_get_contenst()\u3068\u540c\u3058\u304f\u3089\u3044\u7c21\u5358\u306b\u4f7f\u7528\u3067\u304d\u308b\u30e9\u30c3\u30d1\u95a2\u6570\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<br \/>\n<br \/>\n<br \/>\n<br \/>\n\u540d\u524d\u306f\u5206\u304b\u308a\u3084\u3059\u304fmulti_file_get_contenst()\u3068\u3057\u307e\u3057\u305f\u3002<br \/>\n<br \/>\n\u547c\u3073\u5074\u306e\u30b3\u30fc\u30c9\u306f\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n<pre lang=\"php\">\n<?php\n$urlList = array();\n$urlList[] = \"http:\/\/www.yahoo.co.jp\/\";\n$urlList[] = \"http:\/\/www.google.com\/\";\n$urlList[] = \"http:\/\/www.infoseek.co.jp\/\";\n$urlList[] = \"http:\/\/www.goo.ne.jp\/\";\n\n\/\/-----------------------------------------\n\/\/ \u8907\u6570URL\u306e\u30c7\u30fc\u30bf\u3092\u975e\u540c\u671f\u3067\u540c\u6642\u306b\u53d6\u5f97\u3059\u308b\n\/\/-----------------------------------------\n$htmlTextList = multi_file_get_contents( $urlList );\n\n\/\/-----------------------------------------\n\/\/ \u53d6\u5f97\u7d50\u679c\u306e\u4f7f\u7528\uff08\u30c7\u30fc\u30bf\u9577\u3092\u30c7\u30d0\u30c3\u30b0\u51fa\u529b\uff09\n\/\/-----------------------------------------\nforeach( $htmlTextList as $htmlText ) {\n    echo \"text length: \" . strlen( $htmlText ) . \"\";\n}\n<\/pre>\n<br \/>\n\u5b9f\u884c\u7d50\u679c<br \/>\n<a href=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/11\/20121112_01.jpg\"><img loading=\"lazy\" src=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/11\/20121112_01.jpg\" alt=\"\" title=\"20121112_01\" width=\"202\" height=\"173\" class=\"alignnone size-full wp-image-5746\" \/><\/a><br \/>\n<br \/>\n<br \/>\n<br \/>\n\u3067\u3001\u5b9f\u969b\u306e\u95a2\u6570\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<br \/>\n<pre lang=\"php\">\n<?php\nfunction multi_file_get_contents( $urlList ) {\n    $resList = array(); \/\/ \u63a5\u7d9a\u60c5\u5831\u306e\u4e00\u89a7\n\n    \/\/------------------------------------\n    \/\/ cUrl\u306e\u30cf\u30f3\u30c9\u30eb\u3092\u53d6\u5f97\n    \/\/------------------------------------\n    $handle = curl_multi_init();\n\n    \/\/------------------------------------\n    \/\/ \u63a5\u7d9a\u6bce\u306e\u30ea\u30bd\u30fc\u30b9\u60c5\u5831\u3092\u4e00\u89a7\u306b\u8ffd\u52a0\n    \/\/------------------------------------\n    foreach ( $urlList as $url ) {\n        $res= curl_init( $url );\n\n        \/\/ CURLOPT_RETURNTRANSFER=true\n        \/\/   ->  curl_multi_getcontent()\u306e\u8fd4\u308a\u5024\u3067\u7d50\u679c\u3092\u53d7\u3051\u53d6\u308b\n        curl_setopt( $res, CURLOPT_RETURNTRANSFER, TRUE );\n\n        curl_multi_add_handle($handle, $res );\n\n        $resList[] = $res;\n    }\n\n    \/\/----------------------------------\n    \/\/ \u975e\u540c\u671f\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\n    \/\/  (\u5168\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u7d42\u308f\u308b\u307e\u3067\u5f85\u3064)\n    \/\/----------------------------------\n    do {\n        curl_multi_exec( $handle, $isRunning );\n    } while ( $isRunning );\n\n    \/\/----------------------------\n    \/\/ \u53d6\u5f97\u3057\u305f\u7d50\u679c\u3092\u914d\u5217\u306b\u683c\u7d0d\n    \/\/----------------------------\n    $htmlTextList = array();\n    foreach ( $resList as $res ) {\n        $htmlTextList[] = curl_multi_getcontent( $res );\n    }\n\n\n    \/\/ \u30ea\u30bd\u30fc\u30b9\u306e\u7834\u68c4\n    foreach ( $resList as $res ) {\n        curl_multi_remove_handle($handle, $res );\n        curl_close( $res );\n    }\n\n    curl_multi_close( $handle );\n\n    \/\/ \u53d6\u5f97\u7d50\u679c\u3092\u8fd4\u3059\n    return $htmlTextList;\n}\n<\/pre>\n<br \/>\n<br \/>\n<br \/>\n<br \/>\nPHP\u306e\u5b9f\u884c\u74b0\u5883\u306b\u3088\u3063\u3066\u306f\u3001\u95a2\u6570\u5185\u306b\u3042\u308bcurl_multi_init()\u3067\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u5834\u5408\u304c\u6709\u308a\u307e\u3059\u3002<br \/>\n<a href=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/11\/20121112_02.jpg\"><img loading=\"lazy\" src=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/11\/20121112_02-500x134.jpg\" alt=\"\" title=\"20121112_02\" width=\"500\" height=\"134\" class=\"alignnone size-large wp-image-5744\" srcset=\"http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/11\/20121112_02-500x134.jpg 500w, http:\/\/nanoappli.com\/blog\/wp-content\/uploads\/2012\/11\/20121112_02.jpg 526w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><br \/>\n<pre lang=\"x\">\nFatal error: Call to undefined function curl_multi_init()\n<\/pre>\n<br \/>\n<br \/>\n\u3053\u306e\u3088\u3046\u306a\u5834\u5408\u306fphp.ini\u3092\u7de8\u96c6\u3057\u3001php_curl.dll\u306eextension\u3092\u6709\u52b9\u306b\u3057\u3066\u4e0b\u3055\u3044<br \/>\n<br \/>\n\u7de8\u96c6\u524d<br \/>\n<pre lang=\"x\">\n;;;;;;;;;;;;;;;;;;;;;;\n; Dynamic Extensions ;\n;;;;;;;;;;;;;;;;;;;;;;\n\n;extension=php_curl.dll\n<\/pre>\n\u2193<br \/>\n<br \/>\n<pre lang=\"x\">\n;;;;;;;;;;;;;;;;;;;;;;\n; Dynamic Extensions ;\n;;;;;;;;;;;;;;;;;;;;;;\n\nextension=php_curl.dll\n<\/pre>\n<br \/>\n<br \/>\n<a href=\"http:\/\/www.amazon.co.jp\/gp\/product\/B000GTJSU8\/ref=as_li_ss_il?ie=UTF8&#038;camp=247&#038;creative=7399&#038;creativeASIN=B000GTJSU8&#038;linkCode=as2&#038;tag=nanoappli-22\"><img border=\"0\" src=\"http:\/\/ws.assoc-amazon.jp\/widgets\/q?_encoding=UTF8&#038;ASIN=B000GTJSU8&#038;Format=_SL160_&#038;ID=AsinImage&#038;MarketPlace=JP&#038;ServiceVersion=20070822&#038;WS=1&#038;tag=nanoappli-22\" ><\/a><img loading=\"lazy\" src=\"http:\/\/www.assoc-amazon.jp\/e\/ir?t=nanoappli-22&#038;l=as2&#038;o=9&#038;a=B000GTJSU8\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" \/>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u3067\u306f\u3001file_get_contenst()\u95a2\u6570\u306bURL\u3092\u6307\u5b9a\u3059\u308b\u4e8b\u3067\u3001\u4ed6\u306e\u30b5\u30a4\u30c8\u306ehtml\u30c6\u30ad\u30b9\u30c8\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002 1\u3064\u306e\u30b5\u30a4\u30c8\u3060\u3051\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306f\u3053\u308c\u3067\u3088\u3044\u306e\u3067\u3059\u304c\u3001\u5927\u91cf\u306e\u30b5\u30a4\u30c8\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u3001 1\u30b5\u30a4\u30c8\u3064\u3065\u9806\u756a\u306b\u95a2\u6570\u3092\u547c\u3093\u3067\u3044\u305f\u3089\u975e\u5e38\u306b\u6642\u9593\u304c\u639b\u304b\u308a\u307e\u3059\u3002 \u3053\u306e\u3088\u3046\u306a\u5834\u5408\u306fcURL\u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u6709\u308bcurl_multi_getcontent()\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u8907\u6570\u30b5\u30a4\u30c8\u306e\u60c5\u5831\u3092\u975e\u540c\u671f\u3067\u540c\u6642\u306b\u53d6\u5f97\u51fa\u6765\u307e\u3059\u3002 \u3067\u3059\u304c\u3001curl_multi_getcontent()\u306f\u3001\u30ea\u30bd\u30fc\u30b9\u306e\u78ba\u4fdd\uff65\u958b\u653e\u51e6\u7406\u304c\u5fc5\u8981\u3067\u3001\u6271\u3044\u304c\u3061\u3087\u3063\u3068\u7169\u96d1\u3067\u3059\u3002 \u3053\u306e\u70ba\u3001\u4eca\u56de\u306ffile_get_contenst()\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[22],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2909,"url":"http:\/\/nanoappli.com\/blog\/archives\/2909","url_meta":{"origin":5743,"position":0},"title":"[PHP]\u30e1\u30bd\u30c3\u30c9\u306e\u547c\u3073\u51fa\u3057\u5143\u95a2\u6570\u540d\u3092\u53d6\u5f97\u3059\u308b","date":"2012\u5e745\u670827\u65e5","format":false,"excerpt":"debug_backtrace()\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u30b9\u30bf\u30c3\u30af\u30c8\u30ec\u30fc\u30b9\u306e\u60c5\u5831\u304b\u3089\u53d6\u5f97\u53ef\u80fd\u3067\u3059\u3002 f\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":768,"url":"http:\/\/nanoappli.com\/blog\/archives\/768","url_meta":{"origin":5743,"position":1},"title":"[JavaScript]\u914d\u5217\u4e2d\u306e\u5927\u91cf\u30c7\u30fc\u30bf\u3092\u975e\u540c\u671f\u3067\u3086\u3063\u304f\u308a\u51e6\u7406\u3059\u308b","date":"2012\u5e741\u670826\u65e5","format":false,"excerpt":"\u5148\u65e5\u3001\u30af\u30ed\u30cd\u30b3\u30e4\u30de\u30c8\u306e\u4f1d\u7968\u756a\u53f7\u304b\u3089\u914d\u9001\u72b6\u6cc1\u3092\u53d6\u5f97\u3059\u308bAPI\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002 \u3053\u306eAPI\u3067\u3059\u304c\u3001\u8ca0\u8377\u8efd\u6e1b\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3033,"url":"http:\/\/nanoappli.com\/blog\/archives\/3033","url_meta":{"origin":5743,"position":2},"title":"xpath\u3067\u8907\u6570\u306eclass\u304c\u6307\u5b9a\u3055\u308c\u305f\u30bf\u30b0\u3092\u53d6\u5f97\u3059\u308b","date":"2012\u5e745\u670831\u65e5","format":false,"excerpt":"xml\u306e\u30c7\u30fc\u30bf\u304b\u3089\u7279\u5b9a\u306e\u30bf\u30b0(\u30ce\u30fc\u30c9)\u3092\u53d6\u5f97\u3059\u308b\u306b\u306fxpath\u3092\u6307\u5b9a\u3059\u308b\u3068\u4fbf\u5229\u3067\u3059\u3002 \u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1421,"url":"http:\/\/nanoappli.com\/blog\/archives\/1421","url_meta":{"origin":5743,"position":3},"title":"[JavaScript]\u5373\u6642\u95a2\u6570\u306e\u547c\u3073\u51fa\u3057\u304c,\u306a\u305c\u300c(function(){&#8230;})()\u300d\u306e\u5f62\u5f0f\u306b\u306a\u308b\u304b\u8aac\u660e\u3057\u3066\u307f\u308b\u3002","date":"2012\u5e742\u670821\u65e5","format":false,"excerpt":"JavaScript\u3067\u306f\u5373\u6642\u95a2\u6570\u3068\u3044\u3046\u4ed5\u7d44\u307f\u304c\u3042\u308a\u307e\u3059\u3002 \u5373\u6642\u95a2\u6570\u306f\u3001\u30b0\u30ed\u30fc\u30d0\u30eb\u306a\u540d\u524d\u7a7a\u9593\u3092\u6c5a\u3055\u306a\u3044\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5202,"url":"http:\/\/nanoappli.com\/blog\/archives\/5202","url_meta":{"origin":5743,"position":4},"title":"[C# 5.0]\u30e1\u30bd\u30c3\u30c9\u306e\u547c\u3073\u5143\u30e1\u30bd\u30c3\u30c9\u3092\u8abf\u3079\u308b\u65b9\u6cd5","date":"2012\u5e7410\u670827\u65e5","format":false,"excerpt":"C# 5.0\u3067\u306f\u3001\u95a2\u6570\u306e\u5f15\u6570\u306b\u5c5e\u6027(attribute)\u3092\u8ffd\u52a0\u3059\u308b\u4e8b\u3067\u3001\u95a2\u6570\u306e\u547c\u3073\u5143\u306e\u60c5\u5831\u3092\u53d6\u5f97\u304c\u53ef\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7392,"url":"http:\/\/nanoappli.com\/blog\/archives\/7392","url_meta":{"origin":5743,"position":5},"title":"[PHP]echo\u3084print\u306f\u95a2\u6570\u306a\u306e\u304b?\u305d\u308c\u3068\u3082\u8a00\u8a9e\u69cb\u9020\u306a\u306e\u304b?","date":"2016\u5e744\u67085\u65e5","format":false,"excerpt":"PHP\u3067\u306fecho\u3092\u4f7f\u3063\u3066\u3082\u3001print\u3092\u4f7f\u3063\u3066\u3082\u753b\u9762\u306b\u6587\u5b57\u3092\u51fa\u529b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \u3053\u308c\u3089\u306fec\u2026","rel":"","context":"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/5743"}],"collection":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/comments?post=5743"}],"version-history":[{"count":13,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/5743\/revisions"}],"predecessor-version":[{"id":5767,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/posts\/5743\/revisions\/5767"}],"wp:attachment":[{"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/media?parent=5743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/categories?post=5743"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nanoappli.com\/blog\/wp-json\/wp\/v2\/tags?post=5743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}