我想制作可以从网页中获取文本的 php 代码。该代码从网站获取文本,然后搜索以“N”开头并以“a”结尾的文本,然后脚本将其添加到数组 [0]。我在正则表达式中的错误,请帮助我修复它,对不起我的英语不好
这是我的代码:
<?php
$url = "http://www.nokia.com/global/products/phone/lumia820/";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_exec($ch);
curl_close($ch);
preg_match_all('/^N(.*)\a$/', $result, $matches[0]);
preg_match_all('/^M(.*)\m$/', $result, $matches[0]);
preg_match_all('/^M(.*)\c$/', $result, $matches[0]);
print_r($matches[0]);
?>
如果我尝试使用 html hor 示例,如何将 700 mAh 作为阵列 [0]、BL-5CA 作为阵列 [2]、诺基亚作为阵列 [3]
<div class="b-goods-specifications mod_cutted"> <div class="b-goods-specifications-item"> <ul class="b-goods-specifications-list"> <li class = "b-goods-specifications-row g-clearfix "> <div class="b-goods-specifications-cell"> <span> **capacity** </ span> </ div> <div class="b-goods-specifications-cell"> **700 mAh** </ div> </ li> <li class="b-goods-specifications-row g-clearfix"> <div class="b-goods-specifications-cell"> <span> **Model** </ span> </ div > <div class="b-goods-specifications-cell"> **BL-5CA** </ div> </ li> <li class="b-goods-specifications-row g-clearfix"> <div class = "b-goods-specifications-cell "> <span> **Brand** </ span> </ div> <div class="b-goods-specifications-cell"> **Nokia** </ div> </ li> <li class =" b-goods -specifications-row g-clearfix "> <div class="b-goods-specifications-cell"> <span> Type </ span> </ div> <div class="b-goods-specifications-cell"> Li -ion </ div> </ li> </ ul> </ div> </ div>