Php 如何仅在正则表达式中以键/值对的形式从表行中获取内容

Php 如何仅在正则表达式中以键/值对的形式从表行中获取内容,php,regex,html-table,Php,Regex,Html Table,我有这张桌子: <?php $a ="<table class='table table-condensed'> <tr> <td>Monthely rent</td> <td><strong>Fr. 1'950. </strong></td> </tr> <tr> <td>Rooms(s)</td> <td><strong&

我有这张桌子:

<?php 
$a ="<table class='table table-condensed'>
<tr>
<td>Monthely rent</td>
<td><strong>Fr. 1'950. </strong></td>
</tr>

<tr>
<td>Rooms(s)</td>
<td><strong>3</strong></td>
</tr>

<tr>
<td>Surface</td>
<td><strong>93m2</strong></td>

</tr>

<tr>
<td>Date of Contract</td>
<td><strong>01.04.17</strong></td>
</tr>

</table>
到目前为止,只有这段代码返回一些接近我需要的结果,但与我期望的格式不同

preg_match_all("/<td>.*/", $a, $matches);
preg_match_all(“/.*/”,$a,$matches);
我正试图找到这方面的任何改进。

您可以使用以下正则表达式从表行中获取作为键/值对的内容:

regex获取密钥>>(?>(?)?

可能重复@PaulCrovella前面的问题涉及DOM,主要是一个DOM问题,而这是一个仅限正则表达式的问题(请参见标题)。这很好,但仍然无法获得数组/键值对。var_dump($result)给出了所有数组值的文本,我尝试回显$1,但也不起作用,似乎唯一剩下的是通过regex再次解析$result的输出again@user7342807检查更新的答案。现在它应该如您所期望的那样工作。谢谢,虽然它只返回值,但键没有名称,但我现在就做
preg_match_all("/<td>.*/", $a, $matches);
regex to get keys  >>  (?<=<td>)(?!<strong>).*?(?=<\/td>)
   . . .   values  >>  (?<=<strong>).*?(?=<\/strong>)
<?php
$re = '/(?<=<strong>).*?(?=<\/strong>)/';
$str = '<table class=\'table table-condensed\'>
        <tr>
        <td>Monthly rent</td>
        <td><strong>Fr. 1\'950. </strong></td>
        </tr>
        <tr>
        <td>Rooms(s)</td>
        <td><strong>3</strong></td>
        </tr>
        <tr>
        <td>Surface</td>
        <td><strong>93m2</strong></td>
        </tr>
        <tr>
        <td>Date of Contract</td>
        <td><strong>01.04.17</strong></td>
        </tr>
        </table>';
preg_match_all($re, $str, $matches);
print_r($matches);
?>