PHP中的站点地图解析问题

时间:2019-02-05 20:07:43

标签: php xml sitemap

我正在尝试使用sitemap.xml来解析PHP

我已经测试了几种方法。

1)通过xml PHP方法获取并加载simplexml_load_string字符串。一般而言,我是在loc节点中获取url

<url>
    <loc>http://example.com/</loc>
    <lastmod>2010-09-29T10:38:11+00:00</lastmod>
    <changefreq>monthly</changefreq>
</url>

但是 如果节点是这样的话,这会立即引起问题。

<ns1:url>
    <ns1:loc>https://www.example.com/</ns1:loc>
    <ns1:changefreq>daily</ns1:changefreq>
    <ns1:priority>1</ns1:priority>
</ns1:url>

上面的方法没有解析这种响应。 所以我选择了Regular expressions

2)我尝试使用此RE在loc中抓取内容。 /loc>(.*?)</

我这样执行。

preg_match_all($expression, $sitemap, $matches);

$matches变量仅产生12个网址。 preg_match_all有什么限制吗?如果可以的话,该如何克服?

任何帮助或建议都是巨大的帮助。

TIA。

PS。 sitemap.xml文件中有超过200个网址。

0 个答案:

没有答案