0

I have this string:

$str = '<td class="title">Genre:</td><td class="detail"><a href="/en-us/store/browse/action">   Action   </a></td></tr>';
$str2 = '<td class="title">Release Date:</td><td class="detail">   January 13 2009  </td></tr>';

I need to get an associative array structured like this:

$arr[$title] = $detail;

My problem is not the pattern itself, but how to create an array. Thanks for any help.

Xriuk
  • 382
  • 2
  • 7
  • 26

1 Answers1

1

If your regexp is like this

$re = '~<td class="title">(.+?):</td><td class="detail">(.+?)</td>~';

then you can simply do

preg_match($re, $str, $matches);
$arr[$matches[1]] = $matches[2];

Do note however, that regexes is not the best way to parse html.

georg
  • 211,518
  • 52
  • 313
  • 390