PHP正则表达式基于模式创建关联数组

PHP正则表达式基于模式创建关联数组,php,regex,Php,Regex,我有这个字符串: $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

我有这个字符串:

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

我的问题不是模式本身,而是如何创建数组。谢谢您的帮助。

如果您的regexp是这样的话

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

但是请注意,正则表达式并不是解析html的最佳方式。

解析html的最佳方式是什么?@Xriuk:
$re = '~<td class="title">(.+?):</td><td class="detail">(.+?)</td>~';
preg_match($re, $str, $matches);
$arr[$matches[1]] = $matches[2];