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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.