473,320 Members | 1,535 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,320 software developers and data experts.

preg_match and html question


I need a regular expression for preg_match to find all of the strings between
'>' and '<' from html. Eg.

1. <TD><FONT SIZE='2'>XXX</FONT></TD>
2. <TD><FONT SIZE='2'><A HREF=http://www.whatever.com/...7>ZZZ</A></FONT></TD>
3. <TD ALIGN=CENTER><FONT SIZE='2'>Y/Y</FONT></TD>

#1 matches should be "", "XXX", and ""
#2 should be "", "", "ZZZ", "", ""
#3 should be "", "Y/Y", ""

Actually I need only the non-empty strings, but I can just ignore the empty ones.

I've tried preg_match("/>(.*)</i", $str, $matches) but it doesn't work like I want.
Does anyone know how to get this to work?

thanks,
Sam

Jun 10 '07 #1
3 3000
Sam Waller wrote:
I need a regular expression for preg_match to find all of the strings between
'>' and '<' from html. Eg.

1. <TD><FONT SIZE='2'>XXX</FONT></TD>
2. <TD><FONT SIZE='2'><A HREF=http://www.whatever.com/...7>ZZZ</A></FONT></TD>
3. <TD ALIGN=CENTER><FONT SIZE='2'>Y/Y</FONT></TD>

#1 matches should be "", "XXX", and ""
#2 should be "", "", "ZZZ", "", ""
#3 should be "", "Y/Y", ""

Actually I need only the non-empty strings, but I can just ignore the empty ones.

I've tried preg_match("/>(.*)</i", $str, $matches) but it doesn't work like I want.
Does anyone know how to get this to work?

thanks,
Sam

strip_tags() :-)

--
Arjen
http://www.arjenkarel.nl
Jun 10 '07 #2
On 10.06.2007 17:23 Sam Waller wrote:
I need a regular expression for preg_match to find all of the strings between
'>' and '<' from html. Eg.

1. <TD><FONT SIZE='2'>XXX</FONT></TD>
2. <TD><FONT SIZE='2'><A HREF=http://www.whatever.com/...7>ZZZ</A></FONT></TD>
3. <TD ALIGN=CENTER><FONT SIZE='2'>Y/Y</FONT></TD>

#1 matches should be "", "XXX", and ""
#2 should be "", "", "ZZZ", "", ""
#3 should be "", "Y/Y", ""

Actually I need only the non-empty strings, but I can just ignore the empty ones.

I've tried preg_match("/>(.*)</i", $str, $matches) but it doesn't work like I want.
Does anyone know how to get this to work?

thanks,
Sam
Try using a character class instead of dot: />([^<>]*)</

--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Jun 11 '07 #3
gosha bine wrote:
Try using a character class instead of dot: />([^<>]*)</
Also, using + instead of * might work better for your purposes.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 107 days, 22:28.]

URLs in demiblog
http://tobyinkster.co.uk/blog/2007/05/31/demiblog-urls/
Jun 11 '07 #4

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

Similar topics

2
by: Han | last post by:
I'm wondering if someone can explain why the following works with preg_match_all, but not preg_match: $html = "product=3456789&amp;" preg_match_all ("|product=(\d{5,10})&amp;|i", $html, $out); $out...
14
by: Westcoast Sheri | last post by:
What is the most efficient way of extracting the first two digits in a string? The following is wrong for me, because it only gives me the first instance of two digits together: $string =...
10
by: aaron | last post by:
I need some help with validating an email address. Right now, I am doing this: function sys_is_valid_email ($s) { if (preg_match ("/^.+@.+\..+$/", $s)) { return 1; } else { return 0; } }
2
by: Muumac | last post by:
I have problem with large textfiles! When I load over 4MB xml and then try to preg_match something in this I get always FALSE! I have <File>....</File> tags in XML. Between tags is files contents...
4
by: DH | last post by:
I need to parse some HTML tags and display the style classes, and have it partly working, but need some regex / preg_match advise. If the tag is <td class="red" colspan="1"> I can display...
5
by: Mark Woodward | last post by:
Hi all, I'm trying to validate text in a HTML input field. How do I *allow* a single quote? // catch any nasty characters (eg !@#$%^&*()/\) $match = '/^+$/'; $valid_srch = preg_match($match,...
4
by: cainwebdesign | last post by:
I need to create a simple page to find the .gif file below from the page below. No matter what I try it doesn't work.... Any ideas? http://www.toysrus.com/product/index.jsp?productId=2327085 ...
7
by: Chuck Anderson | last post by:
I am trying to implement email injection protection by looking for \r and/or \n in the name, subject, or email address fields from my contact form The first script, contact_us.php, contains a...
3
by: fienen | last post by:
I am working on a script to handle a search query. In some instances, the query could come through as "isbn:%20#############" (where %20 is an encoded space and the colon is optional). Basically...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.