?
Solved

Converting html table data into usable arrays

Posted on 2003-03-10
4
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

801 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