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?

4
  • Which prior research led you to this intended solution, but without usable examples? Commented Jan 22, 2015 at 17:46
  • Don't use regex to parse HTML. stackoverflow.com/questions/1732348/… I'll write up an answer in a few moments. Commented Jan 22, 2015 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. Commented Jan 22, 2015 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. Commented Jan 22, 2015 at 18:00

2 Answers 2

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
)
Sign up to request clarification or add additional context in comments.

1 Comment

Don't use regex to parse HTML, they should use DOMDoc.
-1
$pattern = "/<td class=\"nfo\">(.*?)<\/td>/s";
preg_match($pattern, $stringtomatch, $matches);
echo $matches[1];

Result

16 GB, 1 GB RAM

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.