PHPを使用して配列からURLデータを取得しようとすると、いくつかの問題が発生します。
私のコードは、robots.txt ファイルに記載されている各サイトマップを取得しようとしています。
$robots_file = file_get_contents($robotsTXT);
$pattern = "/Sitemap: ([^\r\n]*)/";
$i = preg_match_all($pattern, $robots_file, $match, PREG_SET_ORDER);
print_r($match);
print_r($マッチ); 以下に戻ります
Array (
[0] => Array ( [0] => Sitemap: http://www.google.com/culturalinstitute/sitemap.xml
[1] => http://www.google.com/culturalinstitute/sitemap.xml )
[1] => Array ( [0] => Sitemap: http://www.google.com/hostednews/sitemap_index.xml
[1] => http://www.google.com/hostednews/sitemap_index.xml )
[2] => Array ( [0] => Sitemap: http://www.google.com/sitemaps_webmasters.xml
[1] => http://www.google.com/sitemaps_webmasters.xml )
[3] => Array ( [0] => Sitemap: http://www.google.com/ventures/sitemap_ventures.xml
[1] => http://www.google.com/ventures/sitemap_ventures.xml )
[4] => Array ( [0] => Sitemap: http://www.gstatic.com/dictionary/static/sitemaps/sitemap_index.xml [1] => http://www.gstatic.com/dictionary/static/sitemaps/sitemap_index.xml )
[5] => Array ( [0] => Sitemap: http://www.gstatic.com/earth/gallery/sitemaps/sitemap.xml
[1] => http://www.gstatic.com/earth/gallery/sitemaps/sitemap.xml )
[6] => Array ( [0] => Sitemap: http://www.gstatic.com/s2/sitemaps/profiles-sitemap.xml
[1] => http://www.gstatic.com/s2/sitemaps/profiles-sitemap.xml )
[7] => Array ( [0] => Sitemap: http://www.gstatic.com/trends/websites/sitemaps/sitemapindex.xml
[1] => http://www.gstatic.com/trends/websites/sitemaps/sitemapindex.xml )
)
私がやりたいのは、そのようにアドレスを表示することです
http://www.google.com/culturalinstitute/sitemap.xml
http://www.google.com/hostednews/sitemap_index.xml
http://www.google.com/sitemaps_webmasters.xml
http://www.google.com/ventures/sitemap_ventures.xml
http://www.gstatic.com/dictionary/static/sitemaps/sitemap_index.xml
http://www.gstatic.com/earth/gallery/sitemaps/sitemap.xml
http://www.gstatic.com/s2/sitemaps/profiles-sitemap.xml
http://www.gstatic.com/trends/websites/sitemaps/sitemapindex.xml
for each ループを書いてみましたが、うまくいきませんでした。
foreach( $match as $sitemap){
echo $sitemap[1];
}
どんな助けでもいただければ幸いです