Jump to content

new to regex first attempt


severndigital

Recommended Posts

I am trying to parse information in an html table

 

here is the table

 

<TABLE BORDER=1 cellspacing=0 cellpadding=3>
<TR><TD><B>Name</B></TD><TD>NAME</TD></TR><TR><TD><B>Address</B></TD><TD>Address 1<br />
Address 2<br />
City State Zip<br />
</TD></TR>
<TR><TD><B>Phone</B></TD><TD>PHONE</TD></TR>
<TR><TD><B>Fax</B></TD><TD>FAX</TD></TR>
<TR><TD><B>URL</B></TD><TD>URL</TD></TR>

<TR><TD><B>E-mail</B></TD><TD>EMAIL</TD></TR>
</TABLE>

 

Ideally i would like to get the info into an array that looks like the table

 

array('Name'=>'NAME',Address'=>'ADDRESS') and so on.

 

but would just settle for an array of any kind.

 

I can do simple string matches, but nothing this complex, could someone please help me out.

 

Thanks in advance..

 

C

Link to comment
https://forums.phpfreaks.com/topic/149310-new-to-regex-first-attempt/
Share on other sites

Sorry dude, but there's nothing there to uniquely identify those things.  If there will be no other tables/td tags before that stuff,  and the first 4 td tags will always have the stuff you want, you could regex that, by just matching stuff between td tags in general, and just taking the first 4 matches:

 

preg_match_all('~<td>.*?</td>~is',$content,$matches);
$info = array($matches[0][0] => $matches[0][1], $matches[0][2] => $matches[0][3]);

OK fair enough .. is there anyway i can extract just that whole table then??

 

for example it is the only table on the page with this as the tag.

 

<TABLE BORDER=1 cellspacing=0 cellpadding=3>

 

once i have isolated that table, i could do a substr or something to get the information out that i need.

 

Thanks again for all the help the tip of the regex iceburg is at least starting to make sense.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.