-2

Possible Duplicate:
How to parse and process HTML with PHP?

I have the following 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>

and I want to parse it and store in an array for example like this:

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.'
);

Thank you for the hints in advance.

Community
  • 1
  • 1

2 Answers2

0

Read this tutorial, no need to use hungry regex engine.

Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52
  • I'm trying to load the XML in a Dom object but after that I'm not able to parse the content of all tags and the text between them. – user1755641 Oct 18 '12 at 08:50
  • @user1755641 Make your HTML/XML valid. Then, parse all the `strong` tags, and the text in between... – Hidde Oct 18 '12 at 08:53
  • Agreed with @Hidde, if your HTML is generated dynamically, then consider to rework it`s generation procedure. – Bud Damyanov Oct 18 '12 at 08:57
-1

Add the valid HTML into a DOMElement object. With it you can select children and extract their HTML/text into variables.

Docs: http://php.net/manual/en/class.domelement.php

Hidde
  • 11,493
  • 8
  • 43
  • 68