这是文字:
<tr>
<td class="ttl"><a href="glossary.php3?term=dynamic-memory">Internal</a></td>
<td class="nfo">16 GB, 1 GB RAM</td>
</tr>
如何使用preg_match从文本中找到16 GB, 1 GB RAM
?
答案 0 :(得分:0)
你可以这样做:
$str = '<tr>
<td class="ttl"><a href="glossary.php3?term=dynamic-memory">Internal</a></td>
<td class="nfo">16 GB, 1 GB RAM</td>
</tr>';
preg_match('/\<td class="nfo"\>(.+?)\<\/td\>/', $str, $matches);
print_r($matches);
结果:
Array
(
[0] => <td class="nfo">16 GB, 1 GB RAM</td>
[1] => 16 GB, 1 GB RAM
)
答案 1 :(得分:-1)
$pattern = "/<td class=\"nfo\">(.*?)<\/td>/s";
preg_match($pattern, $stringtomatch, $matches);
echo $matches[1];
结果
16 GB, 1 GB RAM