Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Converting html table data into usable arrays

Posted on 2003-03-10
4
Medium Priority
?
210 Views
Last Modified: 2008-03-06
I'm trying to convert a lot of static html pages into usable arrays using PHP.
All of the pages follow this same pattern:

*********************************************************
source code can be found at this URL: http://12-250-153-83.client.attbi.com:10/table.html

***************************************************************************

I might have been able to work this if the cities were not bunched into a group.
But I need an array with the keys name, address, city, phone, etc.

Maybe the map links will help? But I need the phone and the name as well

0
Comment
Question by:server_room
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
Hatemben earned 80 total points
ID: 8106904
Hope this will help ;-)

<?php
$content = join( '', file( 'http://12-250-153-83.client.attbi.com:10/table.html' ) );

preg_match('/Selected Business Listings.*/is', $content, $matches);
$content = $matches[0];
preg_match_all('/<TD[^>]*>(.*)><\/TD>/U', $content, $matches);
foreach($matches[1] as $key=>$val)
{
     $res[$key] = strip_tags(str_replace("&nbsp;","" , $val));
}

$i = 0;
$j = 0;
$first = true;
foreach($res as $val)
{
     if (ereg("NM",$val))
     {
          $citname = $val;
          $data[$i][city] = $citname;
          if (!$first)
          {
               continue;
          }
          $first = false;
     }
     
     $data[$i][city] = $citname;
     
     if ($j == 1)
     {
          $data[$i][name] = $val;
     }
     if ($j == 2)
     {
          $data[$i][address] = $val;
     }
     if ($j == 3)
     {
          $data[$i][phone] = $val;
          $i++;
          $j = 0;
     }    
     $j ++;
}
echo "<pre>";
print_r($data);
echo "</pre>";
?>
0
 
LVL 15

Expert Comment

by:VGR
ID: 8109380
crazy you Hatemben ;-)
0
 
LVL 1

Author Comment

by:server_room
ID: 8111518
This is a wonderful script, but is there a way to make it so that I don't have to put the state for each different html page?

because I have like 3,000 of these :(, if not I know of a way to match the states up with a coresponding database.

Great job btw!
0
 
LVL 2

Expert Comment

by:Hatemben
ID: 8117468
You can browse your 3000 files and get the state name with a preg_match ..., then inject it in this script and do the rest of the job ...

Just try it with 2 or 3 files manually, then you can do it with all the rest :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question