像接受的答案这样的基于正则表达式的解决方案不是从 HTML 文档中提取信息的正确方法。
改用这样的DOMDocument
基于解决方案:
$str = '<table class="table2" style="width:85%; text-align:center">
<tr>
<th>Refference ID</th>
...
<th>Slot</th>
</tr>
<tr>
<td>130717919020ffqClE0nRaspoB</td>
...
<td>20130717091902413</td>
</tr>
</table>';
// Create a document out of the string. Initialize XPath
$doc = new DOMDocument();
$doc->loadHTML($str);
$selector = new DOMXPath($doc);
// Query the values in a stable and easy to maintain way using XPath
$refResult = $selector->query('//table[@class="table2"]/tr[2]/td[1]');
$slotResult = $selector->query('//table[@class="table2"]/tr[2]/td[6]');
// Check if the data was found
if($refResult->length !== 1 || $slotResult->length !== 1) {
die("Data is corrupted");
}
// XPath->query always returns a node set, even if
// this contains only a single value.
$refId = $refResult->item(0)->nodeValue;
$slot = $slotResult->item(0)->nodeValue;
echo "RefId: $refId, Slot: $slot", PHP_EOL;