Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 12th, 2008, 07:03 AM
livewire1974 livewire1974 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 2 livewire1974 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 51 sec
Reputation Power: 0
Extracting from html using php

Hi,
I am completely new to regexp, but i think i need some to extract some info from a table that i have, maybe somebody can give me some pointers?

here is the html,

Code:
<table width="430"  border="0" cellpadding="4">                     <tr>                       <td width="122" valign="top"><img src="graphics/ice_logo_1.gif"></td>                       <td width="130" valign="top"><p class="style3"><strong>Home Broadband</strong><br /><span class="tool">Wireless <a href="" title="">  <img src="graphics/tooltip.gif" width="10" height="10" border="0"></a></span><br /><em>Cont </em> (36:1) <a href=""  title=""><img src="graphics/tooltip.gif" width="10" height="10" border="0"></a><br>                         </p></td>                      <td width="100" valign="top"><span class="style3">                          <em>Dn</em>  					 3Mbps					  <em><a href="" title=""> <img src="graphics/tooltip.gif" width="10" height="10" border="0"></a></em><br>                           <em>Up</em>                            1Mbps</span>  <span><em><a href="" title=""><strong><img src="graphics/tooltip.gif" width="10" height="10" border="0"></strong></a></em></span></td>                       <td width="78" align="right" valign="top"><p> &euro;37.99 <a href="test" title=""> <strong><img src="graphics/tooltip.gif" width="10" height="10" border="0"></strong></a><br /> 					                        </p>                         </td>                     </tr>                   </table>


can somebody help me get the fields from this?

Reply With Quote
  #2  
Old September 12th, 2008, 08:27 AM
ishnid's Avatar
ishnid ishnid is offline
kill 9, $$;
Dev Shed God 4th Plane (6500 - 6999 posts)
 
Join Date: Sep 2001
Location: Shanghai, An tSín
Posts: 6,894 ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level)ishnid User rank is General 44th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 2 Weeks 1 Day 22 h 36 m 34 sec
Reputation Power: 3885
Generally using your own regexps to parse HTML is a bad idea. I'm not PHP programmer, but I'd be pretty confident there should be HTML parsing libraries available to do this kind of task.

Reply With Quote
  #3  
Old September 12th, 2008, 11:34 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,804 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 17 h 28 m 32 sec
Reputation Power: 6112
This will give you all the contents of the <td> fields:
PHP Code:
 $string = <<<STRING
<table width="430"  border="0" cellpadding="4">                     <tr>                       <td width="122" valign="top"><img src="graphics/ice_logo_1.gif"></td>                       <td width="130" valign="top"><p class="style3"><strong>Home Broadband</strong><br /><span class="tool">Wireless <a href="" title="">  <img src="graphics/tooltip.gif" width="10" height="10" border="0"></a></span><br /><em>Cont </em> (36:1) <a href=""  title=""><img src="graphics/tooltip.gif" width="10" height="10" border="0"></a><br>                         </p></td>                      <td width="100" valign="top"><span class="style3">                          <em>Dn</em>                       3Mbps                      <em><a href="" title=""> <img src="graphics/tooltip.gif" width="10" height="10" border="0"></a></em><br>                           <em>Up</em>                            1Mbps</span>  <span><em><a href="" title=""><strong><img src="graphics/tooltip.gif" width="10" height="10" border="0"></strong></a></em></span></td>                       <td width="78" align="right" valign="top"><p> &euro;37.99 <a href="test" title=""> <strong><img src="graphics/tooltip.gif" width="10" height="10" border="0"></strong></a><br />                                             </p>                         </td>                     </tr>                   </table>
STRING;

preg_match_all("#<td[^>]*>(.+?)</td#"$string$foo);
print_r($foo[1]); 
However, it also includes plenty of HTML. If the HTML is properly formed, you can use the DOM document model to parse it, but I personally like using regexp for this sort of thing.

-Dan
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Extracting from html using php

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap