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
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]);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.