使用正则表达式获取数据

时间:2012-06-13 10:31:43

标签: php

我希望获取此元标记<meta content="Rs.55.09" itemprop="price">中的内容或紧跟元标记(<meta content="Rs.55.09" itemprop="price"> Rs.55.09)之后的内容,即需要产品的价格。是否有任何正则表达式来获取数据。

提前致谢...

1 个答案:

答案 0 :(得分:3)

这有效:

preg_match('/<meta content=\"(.*?)\" itemprop=\"price\">/i', $data, $matches);

但是,我强烈建议您查看DOMDocument或其他HTML解析器,因为不建议使用正则表达式来解析HTML。

Read more about HTML parsers hereread more about why not to use regex here

相关问题