Jump to content

Whats the best way to place this into mysql


twittoris

Recommended Posts

What would be the best way to break the following html into a table

 

<div class="highlight">Name: CHRISTOPHER</div>

      <table summary="This table contains status information for the selected name.">

        <caption>Selected name status Information</caption>

        <tr>

            <th>Current Name:</th>

            <td>CHRISTOPHER</td>

        </tr>

        <tr>

            <th>Initial Filing Date:</th>

            <td>DECEMBER  15, 1997</td>

        </tr>

        <tr>

            <th>County:</th>

            <td>NEW YORK</td>

        </tr>

        <tr>

            <th>Jurisdiction:</th>

            <td>NEW YORK</td>

        </tr>

        <tr>

            <th>Type:</th>

            <td>Full Member</td>

        </tr>

 

 

Would pregmatch or COMDocument be easier?

 

I would instantiate a DOMDocument object, and use the getElementsByTagName to gather the <TH> and <TD> tags. With arrays of the TH and TD tags, I would use a for loop through the TH tags, using a switch on innerHTML with cases for each label (ex: Current Name:) and grab the corresponding <TD> tags innerHTML.

 

This is a basic solution for the HTML you've provided me, given there are an equal number of TH to TD tags. Once the HTML includes other tables without a 1:1 relational ratio this solution suffers model breakdown.

I tried to do it this way:

 

// make the cURL request to $target_url

$html2 = curl_exec($ch2);

 

// parse the html into a DOMDocument

$dom2 = new DOMDocument();

@$dom2->loadHTML($html2);

 

    /*** discard white space ***/

    $dom2->preserveWhiteSpace = false;

 

    /*** the table by its tag name ***/

    $tables = $dom2->getElementsByTagName('table');

 

    /*** get all rows from the table ***/

    $rows2 = $tables->item(0)->getElementsByTagName('tr');

 

    /*** loop over the table rows ***/

    foreach ($rows2 as $row2);

    {

        /*** get each column by tag name ***/

        $cols = $row2->getElementsByTagName('td');

        /*** echo the values ***/

        echo $cols->item(0)->nodeValue.'<br />';

        echo $cols->item(1)->nodeValue.'<br />';

echo $cols->item(2)->nodeValue.'<br />';

        echo $cols->item(3)->nodeValue.'<br />';

        echo $cols->item(4)->nodeValue;

        echo '<hr />';

 

 

 

But it isnt returning anything except the word ACTIVE which is the last table value in HTML.

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.