21,873
社区成员




<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://localhost/</loc>
<lastmod>2015-08-22T11:04:37+00:00</lastmod>
<changefreq>always</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>http://localhost/?post=362</loc>
<lastmod>2015-08-22T10:14:51+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost/?post=361</loc>
<lastmod>2015-08-22T08:01:12+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
$s =<<< XML
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://localhost/</loc>
<lastmod>2015-08-22T11:04:37+00:00</lastmod>
<changefreq>always</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>http://localhost/?post=362</loc>
<lastmod>2015-08-22T10:14:51+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost/?post=361</loc>
<lastmod>2015-08-22T08:01:12+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
</urlset>
XML;
$x = simplexml_load_string($s);
print_r($x);
SimpleXMLElement Object
(
[url] => Array
(
[0] => SimpleXMLElement Object
(
[loc] => http://localhost/
[lastmod] => 2015-08-22T11:04:37+00:00
[changefreq] => always
[priority] => 1.0
)
[1] => SimpleXMLElement Object
(
[loc] => http://localhost/?post=362
[lastmod] => 2015-08-22T10:14:51+00:00
[changefreq] => weekly
[priority] => 0.8
)
[2] => SimpleXMLElement Object
(
[loc] => http://localhost/?post=361
[lastmod] => 2015-08-22T08:01:12+00:00
[changefreq] => weekly
[priority] => 0.8
)
)
)
可知foreach($x->url as $v) $r[] = $v->loc;
file_put_contents('文件.txt', join(PHP_EOL, $r));