473,388 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

In search of a span of class.

Within a subsection of an HTML document (not a complete page), there will be
a few spans with the class "room_headings"
e.g.
<span class="room_headings" Double
Room</span>

Can folks suggest some nice ways of extracting all the text contents of such
spans into a list (for use in a drop-down select list)?

TIA
Aug 13 '06 #1
4 1211
Paul Lautman wrote:
Within a subsection of an HTML document (not a complete page), there will be
a few spans with the class "room_headings"
e.g.
<span class="room_headings" Double
Room</span>

Can folks suggest some nice ways of extracting all the text contents of such
spans into a list (for use in a drop-down select list)?
XPath can be used if the contents are valid XML:
$xml = new SimpleXMLElement( '<foo><span
class="room_headings">DoubleRoom</span<span
class="room_headings">DoubleRoom</span><span
class="room_headings1">DoubleRoom</span></foo>');
print_r($xml->xpath('//span[@class="room_headings"]'));

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Aug 13 '06 #2
R. Rajesh Jeba Anbiah wrote:
Paul Lautman wrote:
>Within a subsection of an HTML document (not a complete page), there
will be a few spans with the class "room_headings"
e.g.
<span class="room_headings" Double
Room</span>

Can folks suggest some nice ways of extracting all the text contents
of such spans into a list (for use in a drop-down select list)?

XPath can be used if the contents are valid XML:
$xml = new SimpleXMLElement( '<foo><span
class="room_headings">DoubleRoom</span<span
class="room_headings">DoubleRoom</span><span
class="room_headings1">DoubleRoom</span></foo>');
print_r($xml->xpath('//span[@class="room_headings"]'));
Sadly I doubt that they are valid XML. They are a middle section of an HTML
page. The normal HTML page header tags will not be present either.

I was wondering if there was a good preg call that could accomplish it?
Aug 13 '06 #3
Rik
Paul Lautman wrote:
Within a subsection of an HTML document (not a complete page), there will be
a few spans with the class "room_headings"
e.g.
<span class="room_headings" Double
Room</span>

Can folks suggest some nice ways of extracting all the text contents of such
spans into a list (for use in a drop-down select list)?
preg_match_all('|<span[^>]*?class="room_headings"[^>]*?>(.*?)</span>|si',$html,$matches,
PREG_PATTERN_ORDER);
print_r($matches[1]);

Grtz,
--
Rik Wasmus
Aug 14 '06 #4
Rik wrote:
Paul Lautman wrote:
>Within a subsection of an HTML document (not a complete page), there
will be a few spans with the class "room_headings"
e.g.
<span class="room_headings" Double
Room</span>

Can folks suggest some nice ways of extracting all the text contents
of such spans into a list (for use in a drop-down select list)?

preg_match_all('|<span[^>]*?class="room_headings"[^>]*?>(.*?)</span>|si',$html,$matches,
PREG_PATTERN_ORDER);
print_r($matches[1]);

Grtz,
That's great, thanks Rik
Aug 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: David Morgan | last post by:
Hello I have a little function to highlight text if it exists. Function Highlight(vFind, vSearch) Dim RegEx Set RegEx = New RegExp RegEx.Pattern = vFind RegEx.IgnoreCase = True Highlight =...
8
by: Someone | last post by:
Hi, I wish to use a dictionary.com search box and want the results of a search to open in a new window. Is there a way to do this using their code? The copy and paste code is provided below. ...
5
by: Martien van Wanrooij | last post by:
I have been using phpdig in some websites but now I stored a lot of larger texts into a mysql database. In the phpdig search engine, when you entered a search word, the page where the search word...
1
by: grabit | last post by:
Hi Peoples i have a search page with a form field "subject" on my results page i have a paging routine . the first page lists its 10 records no trouble but when i click the "next" link i get a error...
2
by: Krustov | last post by:
I wrote this a while ago and found it comes in very handy at times . For example , If you want to know what webpages use a certain stylesheet its just a matter of typing in the stylesheet name...
3
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. ...
1
by: Josiwe | last post by:
I have a search program that returns an HTML string which I display to the user. I want to highlight the search terms. However a simple search and replace on the HTML causes problems. If the...
12
by: iahamed | last post by:
Hi Everyone, I got two parts of my advance search to work, I am running out of Logic to connect the third. My mind is in swing! Pleaseeeeeeeee Help me. I have 3 Fiels to search, the First two...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.