PHP正则表达式以特定方式解析HTML

时间:2012-10-18 08:41:56

标签: php html regex

  

可能重复:
  How to parse and process HTML with PHP?

我有以下HTML:

<Text><strong>Cancellation</strong>
A cancellation is free of charge possible until 6PM on arrival day. With later    cancellation or no arrivals without previous cancellation the hotel is justified to place 90% of the booked achievements (excl. breakfast) in calculation whereby the amount at a value of USD 500.00 is not exceeded.
<strong>Check-in time</strong>
Starting from 15:00
<strong>Check-out time</strong>
Until 12:00
<strong>Guarantee</strong>
No guarantee required.</Text>

我想解析它并存储在一个数组中,例如:

array(
 'Cancelation'    => 'A cancellation is free of charge possible until 6PM on arrival day. With later    cancellation or no arrivals without previous cancellation the hotel is justified to place 90% of the booked achievements (excl. breakfast) in calculation whereby the amount at a value of USD 500.00 is not exceeded.',
 'Check-in time'  => 'Starting from 15:00',
 'Check-out time' => 'Until 12:00',
 'Guarantee'      => 'No guarantee required.'
);

感谢您提前提示。

2 个答案:

答案 0 :(得分:0)

阅读this教程,无需使用饥饿的正则表达式引擎。

答案 1 :(得分:-1)

有效 HTML添加到DOMElement对象中。有了它,您可以选择子项并将其HTML /文本提取到变量中。

文档:http://php.net/manual/en/class.domelement.php

相关问题