0

This is the text:

<tr>
<td class="ttl"><a href="glossary.php3?term=dynamic-memory">Internal</a></td>
<td class="nfo">16 GB, 1 GB RAM</td>
</tr>

How can I find 16 GB, 1 GB RAM from text using preg_match?

Aliyev Rauf
  • 11
  • 1
  • 6
  • Which prior research led you to this intended solution, but without usable examples? – mario Jan 22 '15 at 17:46
  • Don't use regex to parse HTML. http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags I'll write up an answer in a few moments. – Tek Jan 22 '15 at 17:54
  • @Tek Read past the joke answers for once. Parsing ain't matching. And rewarding no-effort questions with meme-compliant but excessively duplicated DOM answers will not educate newbies. – mario Jan 22 '15 at 17:57
  • I believe educating newbies includes telling them to use the proper tools for the job. If you need something from an HTML document regex is not the tool for the job here. Thanks for marking it as duplicate though. – Tek Jan 22 '15 at 18:00

2 Answers2

0

Simply you can do this like this:

$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);

result:

Array
(
    [0] => <td class="nfo">16 GB, 1 GB RAM</td>
    [1] => 16 GB, 1 GB RAM
)
Piotr Olaszewski
  • 6,017
  • 5
  • 38
  • 65
-1
$pattern = "/<td class=\"nfo\">(.*?)<\/td>/s";
preg_match($pattern, $stringtomatch, $matches);
echo $matches[1];

Result

16 GB, 1 GB RAM
fortune
  • 3,361
  • 1
  • 20
  • 30
  • I wasn't the one to down vote you. However, it's probably like I've commented in the other answer. You don't retrieve information from HTML with regex – Tek Jan 22 '15 at 18:02