成对分组数据

时间:2012-10-29 12:18:12

标签: php

  

编辑:我觉得我应该澄清,据我所知,我没有解析问题。我已经在使用DOM和xpath了   感觉足够。我遇到的问题是使用它的逻辑谜语   已在循环中解析结果。

我有一长串HTML,我试图用PHP解析。到目前为止,我有preg_match正在隔离我想要的东西,但我想帮助改进输出。 HTML的格式很差,不是任何标签之间的一个长字符串,但基本上包含标题,后跟一个或多个段落等等。

所以我的preg_match正则表达式正在隔离标题和段落,并且我使用for循环来抓取小于或等于13的结果,因为它们将输出的div具有有限的维度。

标题数量是一个未知变量,每个标题的段落数量也是如此。 我正在尝试做的是确保输出ALWAYS以段落结束,无论之前有多少匹配(有时连续有2个标题。这是一个数据输入问题,我也正在研究它,但对此的控制要少得多)。 我意识到for循环的'小于或等于'部分是有问题的。我认为解决方案是隔离标题 - 段落对然后计算它们,我只是没有取得任何进展。

某种明亮的火花会指向正确的方向吗? :)

我必须使用的字符串示例如下:

<h2 class="border_top">Description:</h2>
<b>Surroundings</b><br /><br />Dunoon is the marine gateway to the Loch Lomond and the Trossachs National Park, and has a number of
local amenities including a cinema, two supermarkets, several choice
restaurants and bars, primary and secondary schools, library, Post
Office, community hospital, doctor surgeries and veterinary clinic,
leisure centre with swimming pool and gym.<br />Innellan has its own
primary school, shop and Post Office. There is a busy village hall and
a popular restaurant nearby. There are a number of clubs in the
Innellan area, including golf, bowling, tennis, cricket and
sailing.<br /><br /><b>Amenities</b><br /><br />A regular local bus
service operates in the area and there are bus and coach services to
popular towns across the West of Scotland. Frequent passenger ferry
services operate from Dunoon Pier to Gourock with regular bus and
train connections to Glasgow Central railway station. The train stops
at Paisley Gilmore Street en route, which is convenient for access to
Glasgow Airport. Western Ferries located at Hunter&#39;s Quay, offers
a regular vehicle service to McInroys Point in Gourock for access to
the national road network.<br /><br /><b>Contact</b><br /><br />To
view this property, please contact <b>Someone Somewhere</b> on <b>01234
467890</b> or <b>09876 543210</b><br /><br /><b>Porch/Vestibule 1.7m x
1.8m</b><br /><br />Modern PVCu wood effect front door set between glazed side panels. Cupboard with electricity meter and room for coats
and boots. Solid wooden flooring and shelving. Glazed door to lower
hall.<br /><br /><b>Lower Hall 2.7m x 3.65m at widest point</b><br
/><br />Provides access to double garage and WC, and to the winding
staircase to lower landing area. Solid wooden flooring.<br /><br
/><b>Downstairs Cloakroom 2m x 0.9m</b><br /><br />Under stairs WC and
wash basin with adequate headroom. Cork effect flooring. Extractor
fan. Fitted shelving.<br /><br /><br /><b>Lower Landing 1.5m x
3.8m</b><br /><br />Carpeted. Large cupboard with double doors, fitted with shelving and hanging rail.<br />Door access to the master bedroom
and stairs up to the next landing.<br /><br /><b>Master Bedroom 4.9m x
5.5m</b><br /><br />This large carpeted area featuring 2 large  length windows, offering fantastic views of the Firth of Clyde and hills on
the opposite shore. There is also a side window making the room
bright. Access from here through door to the walk-in dressing room
area.<br /><br /><b>Dressing Room 3.85m x 2.2m</b><br /><br />Carpeted
with shelving and hanging rails and with plenty of room for additional
storage. Access through door to the en-suite bathroom. Extractor
fan.<br /><br /><b>En-suite 2m x 3.1m</b><br /><br />Walk-in shower
measuring 1100mm x 800mm, chrome towel rail, bidet, WC and wash basin
inset into fitted cupboards. Privacy glazed window and extractor
fan.<br /><br /><b>Main Landing 2.4m x 3.4m</b><br /><br />Solid wood
flooring. High ceiling with Velux roof light. Access to kitchen,
utility room and bedroom/study.<br /><br /><b>Bedroom/Study 4.1m x
4.2m</b><br /><br />This room which is currently used as a study, would be a generous double bedroom. Large fitted wardrobe. Loft
access. Twin windows with amazing views over the river. Solid wooden
flooring.<br /><br /><b>Kitchen 4.6m x 3.5m</b><br /><br
/>Double-doors from the main landing, leads into this bright and
spacious modern fitted kitchen with lots of storage and countertop,
some providing serving access to the dining area. Double window, tiled
splash-backs and hob extractor hood. Solid wooden flooring. Access to
dining area and to Sun Room/Family Room/Office.<br /><br /><b>Dining
Area 4.6m x 4.3m</b><br /><br />Single window in addition to glazed
French doors that open to a small guarded balcony with wonderful sea
views. Solid wooden flooring continues in from the kitchen to this
bright dining area.<br /><br /><b>Sun Room/Family Room/Office 3.1m x
4.3m</b><br /><br />Currently used as an office, this room has a window to the side and two to the back of the house, together with
patio doors which provide access to the decking. This bright and sunny
room has solid wooden flooring.<br /><br /><b>Utility Room 1.65m x
3.05m</b><br /><br />Worktop with stainless steel sink and tiled splash-back. Fitted shelving. Room for washing machine. Modern PVCu
back door with access to decking and garden. Window to garden.<br
/><br /><b>Upper Landing 2.7m x 2.3m</b><br /><br />Carpeted area with
fitted cupboard and access to lounge, bedroom and bathroom.<br /><br
/><b>Bathroom</b><br /><br />Fitted bath with mixer taps. WC and wash
basin inset into fitted cupboard. Shower unit with electric shower.
Cork effect flooring. Privacy glazed double windows and extractor
fan.<br /><br /><b>Bedroom 2.75m x 3.9m</b><br /><br />Peaceful
generous double bedroom with double window looking out onto the back
garden. Large, fitted, double-door wardrobe with fitted shelving and
hanging rail. Carpeted.<br /><br /><b>Lounge 5.5m x 4.2m</b><br /><br
/>Double-door entrance into this bright carpeted area. The lounge
features a total of 6 windows, 2 single side facing at each end, 2
facing the river as well as 2 x  length windows offering fabulous
views of the Firth of Clyde and of the hills on the other side.
Elegant fire surround with living flame gas fire.<br /><br /><b>Double
Garage 6m x 6.5m</b><br /><br />Plenty of room in this double garage,
containing double up and over door and modern gas water heating
system.<br /><br /><b>Garden</b><br /><br />Terraced front garden with
mature planting and additional car parking. Side gate and pathway from
the front of the property leads along the side of the house and up
wooden stairs to timber decking. Decking extends along the rear and
steps up to a small grassed area with flower bed and planters. Pathway
at the other side of the house leads to a planted area at rear of the
house.<br /> <br />                         
<a name="map"></a>

正如您所看到的,它位于2个标签之间,我用它来在HTML文档中找到它。我使用DOM loadHTMLfile然后xpath来查询HTML,但我正在使用preg_match和正则表达式来获取结果中的标题和段落。 上面的标题包括环境,设施,任何0.00米x 0.00米的东西 在这个特定的例子中,标题是粗体标签,但情况并非总是如此。

0 个答案:

没有答案