SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg_match_all tr/td/th problem

    I want all the trs tds and ths extracted
    PHP Code:
    <?php
    $text 
    '
    <table>
    <tr>
    <th>Unit Type</th>
    <th>Availability</th>
    <th>Rates</th>
    </tr>

    <tr>
    <td>One Bedroom</td>
    <td>Call for Availability</td>
    <td>hello</td>
    </tr>

    <tr>
    <td>One Living Room</td>
    <td>Call for Availability</td>
    <td>hello</td>
    </tr>
    </table>'
    ;
    $extract_th="#<th.*>(.+)</th#Ui";
    $extract_tr="/<tr>(.*)<\/tr>/isU";
    $extract_td="/<td.*>(.*)<\/td>/Ui";
    echo 
    $text."<br />\n";
    preg_match_all($extract_tr$text$match_trPREG_SET_ORDER);
    //print_r($match_tr[1][1]);
    for($i=0$i<count($match_tr); $i++){
        for(
    $td=0$td<count($match_tr[$i]); $td++){
            
    preg_match_all($extract_td$match_tr[$i][$td], $match_tdPREG_SET_ORDER);
            
    print_r($match_td[$i]);
        }
    }
    ?>
    I'm getting:
    Code:
    Array
    (
        [0] => <td>Call for Availability</td>
        [1] => Call for Availability
    )
    Array
    (
        [0] => <td>Call for Availability</td>
        [1] => Call for Availability
    )
    Array
    (
        [0] => <td>hello</td>
        [1] => hello
    )
    Array
    (
        [0] => <td>hello</td>
    
        [1] => hello
    )
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title></title>
    </head>

    <body>
    <?php
    $text 
    '<table><tr><th>Unit Type</th><th>Availability</th><th>Rates</th></tr><tr><td>One Bedroom</td><td>Call for Availability</td><td>hello</td></tr><tr><td>One Living Room</td><td>Call not for Availability</td><td>hello</td></tr></table>';
    $extract_th="#<th.*>(.+)</th#Ui";
    $extract_tr="/<tr>(.*)<\/tr>/isU";
    $extract_td="/<td.*>(.*)<\/td>/Ui";


    echo 
    $text."<br />\n";
    preg_match_all($extract_tr$text$match_trPREG_SET_ORDER);
    //print_r($match_tr[1][1]);
    //var_dump($match_tr);
    //echo count($match_tr);

    //print_r($match_tr);
    //print_r($match_tr[0][1]);
    //print_r($match_tr[1][1]);
    //print_r($match_tr[2][1]);

    preg_match($extract_td$match_tr[0][1], $match_th);
    print_r($match_th);

    for(
    $td=1$td<count($match_tr); $td++){
        
    //preg_match_all($extract_td, $match_tr[$td][1], $match_td, PREG_SET_ORDER);
        
    echo "[".$match_tr[$td][1]."]<br />\n";
        
    preg_match($extract_td$match_tr[$td][1], $match_td);
        
    print_r($match_td[$td]);
    }
    ?> 
    </body>
    </html>
    The output:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title></title>
    </head>
    
    <body>
    <table><tr><th>Unit Type</th><th>Availability</th><th>Rates</th></tr><tr><td>One Bedroom</td><td>Call for Availability</td><td>hello</td></tr><tr><td>One Living Room</td><td>Call not for Availability</td><td>hello</td></tr></table><br />
    
    Array
    (
    )
    [<td>One Bedroom</td><td>Call for Availability</td><td>hello</td>]<br />
    One Bedroom[<td>One Living Room</td><td>Call not for Availability</td><td>hello</td>]<br />
     
    </body>
    </html>
    It's not working.
    Compare bible texts (and other tools):
    TheWheelofGod

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $text 
    '<table><tr><th>Unit Type</th><th>Availability</th><th>Rates</th></tr><tr><td>One Bedroom</td><td>Call for Availability</td><td>hello</td></tr><tr><td>One Living Room</td><td>Call not for Availability</td><td>hello</td></tr></table>';
    $extract_th="#<th.*>(.+)</th#Ui";
    //$extract_tr="/<tr>(.*)<\/tr>/isU";
    $extract_tr='@<tr>(.*)<\/tr>@siU';
    $extract_td="/<td.*>(.*)<\/td>/Ui";

    echo 
    $text."<br />\n";
    preg_match_all($extract_tr$text$match_trPREG_SET_ORDER);
    //print_r($match_tr[1][1]);
    //var_dump($match_tr);
    //echo count($match_tr);

    print_r($match_tr);
    echo 
    "[".$match_tr[0][1]."]<br />\n";
    echo 
    "[".$match_tr[1][1]."]<br />\n";
    echo 
    "[".$match_tr[2][1]."]<br />\n";

    //preg_match($extract_td, $match_tr[0][1], $match_th);
    //print_r($match_th);

    for($td=1$td<count($match_tr); $td++){
        
    //preg_match_all($extract_td, $match_tr[$td][1], $match_td, PREG_SET_ORDER);
        //echo "[".$match_tr[$td][1]."]<br />\n";
        
    preg_match($extract_td$match_tr[$td][1], $match_td);
        
    print_r($match_td);
    }
    ?>
    Why is it that the
    PHP Code:
        preg_match($extract_td$match_tr[$td][1], $match_td);
        
    print_r($match_td); 
    in the for loop prints
    Array ( [0] => One Bedroom [1] => One Bedroom ) Array ( [0] => One Living Room [1] => One Living Room )
    and not the whole thing? That's my question.
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Giving this a try....

    PHP Code:
    <!DOCTYPE html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
    <?php
        $text 
    '
            <table>
                <tr>
                    <th>Unit Type</th>
                    <th>Availability</th>
                    <th>Rates</th>
                </tr>
                <tr>
                    <td>One Bedroom</td>
                    <td>Call for Availability</td>
                    <td>hello</td>
                </tr>
                <tr>
                    <td>One Living Room</td>
                    <td>Call not for Availability</td>
                    <td>hello</td>
                </tr>
                <tr>
                    <td>Two Bedrooms</td>
                    <td>Not Availabile</td>
                    <td>Good Bye</td>
                </tr>            
            </table>'
    ;
        echo 
    $text;

        
    $dom = new DOMDocument();
        
    $dom->loadHTML($text);

        
    // Initialize arrays
        
    $thArray $tdArray $array = array();

        
    // Get all Table Headers and throw them in an array
        
    $th $dom->getElementsByTagName('th');
        foreach ( 
    $th as $th ) {
            
    $thArray[] = $th->nodeValue;
        }
        
    // count the array for future comparison
        
    $count count($thArray);
        
        
    /* Example:
            Array
            (
                [0] => Unit Type
                [1] => Availability
                [2] => Rates
            )
        */

        // Get all the Table Cells, but if it matches the same count as the Table Header array, create a new array row
        
    $td $dom->getElementsByTagName('td');
        
    $i 0;
        foreach( 
    $td as $td ) {
            if(
    count($tdArray[$i]) != $count) {
                
    $tdArray[$i][] = $td->nodeValue;
            } else {
                
    $i++;
                
    $tdArray[$i][] = $td->nodeValue;
            }
        }

        
    /* Example
            Array
            (
                [0] => Array
                    (
                        [0] => One Bedroom
                        [1] => Call for Availability
                        [2] => hello
                    )

                [1] => Array
                    (
                        [0] => One Living Room
                        [1] => Call not for Availability
                        [2] => hello
                    )

                [2] => Array
                    (
                        [0] => Two Bedrooms
                        [1] => Not Availabile
                        [2] => Good Bye
                    )

            )
        */    

        // Make a new array based from the tdArray, to match with the thArray's keys 
        
    for( $j 0$j sizeof($thArray); ++$j) {
            foreach( 
    $tdArray as $k=>$v ) {
                
    $array[$j][] = $v[$j];
            }
        }
        
        
    /* Example:
            Array
            (
                [0] => Array
                    (
                        [0] => One Bedroom
                        [1] => One Living Room
                        [2] => Two Bedrooms
                    )

                [1] => Array
                    (
                        [0] => Call for Availability
                        [1] => Call not for Availability
                        [2] => Not Availabile
                    )

                [2] => Array
                    (
                        [0] => hello
                        [1] => hello
                        [2] => Good Bye
                    )

            )
        */    

        
    echo '<pre>';
            
    print_r(array_combine($thArray$array));
        echo 
    '</pre>';

    ?>         
        </body>
    </html>
    Result:
    PHP Code:
    Array
    (
        [
    Unit Type] => Array
            (
                [
    0] => One Bedroom
                
    [1] => One Living Room
                
    [2] => Two Bedrooms
            
    )

        [
    Availability] => Array
            (
                [
    0] => Call for Availability
                
    [1] => Call not for Availability
                
    [2] => Not Availabile
            
    )

        [
    Rates] => Array
            (
                [
    0] => hello
                
    [1] => hello
                
    [2] => Good Bye
            
    )



  5. #5
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by centered effect View Post
    Giving this a try....

    PHP Code:
    <!DOCTYPE html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
    <?php
        $text 
    '
            <table>
                <tr>
                    <th>Unit Type</th>
                    <th>Availability</th>
                    <th>Rates</th>
                </tr>
                <tr>
                    <td>One Bedroom</td>
                    <td>Call for Availability</td>
                    <td>hello</td>
                </tr>
                <tr>
                    <td>One Living Room</td>
                    <td>Call not for Availability</td>
                    <td>hello</td>
                </tr>
                <tr>
                    <td>Two Bedrooms</td>
                    <td>Not Availabile</td>
                    <td>Good Bye</td>
                </tr>            
            </table>'
    ;
        echo 
    $text;

        
    $dom = new DOMDocument();
        
    $dom->loadHTML($text);

        
    // Initialize arrays
        
    $thArray $tdArray $array = array();

        
    // Get all Table Headers and throw them in an array
        
    $th $dom->getElementsByTagName('th');
        foreach ( 
    $th as $th ) {
            
    $thArray[] = $th->nodeValue;
        }
        
    // count the array for future comparison
        
    $count count($thArray);
        
        
    /* Example:
            Array
            (
                [0] => Unit Type
                [1] => Availability
                [2] => Rates
            )
        */

        // Get all the Table Cells, but if it matches the same count as the Table Header array, create a new array row
        
    $td $dom->getElementsByTagName('td');
        
    $i 0;
        foreach( 
    $td as $td ) {
            if(
    count($tdArray[$i]) != $count) {
                
    $tdArray[$i][] = $td->nodeValue;
            } else {
                
    $i++;
                
    $tdArray[$i][] = $td->nodeValue;
            }
        }

        
    /* Example
            Array
            (
                [0] => Array
                    (
                        [0] => One Bedroom
                        [1] => Call for Availability
                        [2] => hello
                    )

                [1] => Array
                    (
                        [0] => One Living Room
                        [1] => Call not for Availability
                        [2] => hello
                    )

                [2] => Array
                    (
                        [0] => Two Bedrooms
                        [1] => Not Availabile
                        [2] => Good Bye
                    )

            )
        */    

        // Make a new array based from the tdArray, to match with the thArray's keys 
        
    for( $j 0$j sizeof($thArray); ++$j) {
            foreach( 
    $tdArray as $k=>$v ) {
                
    $array[$j][] = $v[$j];
            }
        }
        
        
    /* Example:
            Array
            (
                [0] => Array
                    (
                        [0] => One Bedroom
                        [1] => One Living Room
                        [2] => Two Bedrooms
                    )

                [1] => Array
                    (
                        [0] => Call for Availability
                        [1] => Call not for Availability
                        [2] => Not Availabile
                    )

                [2] => Array
                    (
                        [0] => hello
                        [1] => hello
                        [2] => Good Bye
                    )

            )
        */    

        
    echo '<pre>';
            
    print_r(array_combine($thArray$array));
        echo 
    '</pre>';

    ?>         
        </body>
    </html>
    Result:
    PHP Code:
    Array
    (
        [
    Unit Type] => Array
            (
                [
    0] => One Bedroom
                
    [1] => One Living Room
                
    [2] => Two Bedrooms
            
    )

        [
    Availability] => Array
            (
                [
    0] => Call for Availability
                
    [1] => Call not for Availability
                
    [2] => Not Availabile
            
    )

        [
    Rates] => Array
            (
                [
    0] => hello
                
    [1] => hello
                
    [2] => Good Bye
            
    )


    But I want the array to be by row and not by column because I want to insert them in the db table row by row.
    Compare bible texts (and other tools):
    TheWheelofGod

  6. #6
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can just combine the thArray & tdArrays like so:
    PHP Code:
    <!DOCTYPE html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
    <?php
        $text 
    '
            <table>
                <tr>
                    <th>Unit Type</th>
                    <th>Availability</th>
                    <th>Rates</th>
                </tr>
                <tr>
                    <td>One Bedroom</td>
                    <td>Call for Availability</td>
                    <td>hello</td>
                </tr>
                <tr>
                    <td>One Living Room</td>
                    <td>Call not for Availability</td>
                    <td>hello</td>
                </tr>
                <tr>
                    <td>Two Bedrooms</td>
                    <td>Not Availabile</td>
                    <td>Good Bye</td>
                </tr>            
            </table>'
    ;
        echo 
    $text;

        
    $dom = new DOMDocument();
        
    $dom->loadHTML($text);

        
    // Initialize arrays
        
    $thArray $tdArray $array = array();

        
    // Get all Table Headers and throw them in an array
        
    $th $dom->getElementsByTagName('th');
        foreach ( 
    $th as $th ) {
            
    $thArray[] = $th->nodeValue;
        }
        
    // count the array for future comparison
        
    $count count($thArray);
        
        
    /* Example:
            Array
            (
                [0] => Unit Type
                [1] => Availability
                [2] => Rates
            )
        */

        // Get all the Table Cells, but if it matches the same count as the Table Header array, create a new array row
        
    $td $dom->getElementsByTagName('td');
        
    $i 0;
        foreach( 
    $td as $td ) {
            if(
    count($tdArray[$i]) != $count) {
                
    $tdArray[$i][] = $td->nodeValue;
            } else {
                
    $i++;
                
    $tdArray[$i][] = $td->nodeValue;
            }
        }

        echo 
    '<pre>';
            
    print_r(array_combine($thArray$tdArray));
        echo 
    '</pre>';

    ?>         
        </body>
    </html>
    Gives you:
    PHP Code:
    Array
    (
        [
    Unit Type] => Array
            (
                [
    0] => One Bedroom
                
    [1] => Call for Availability
                
    [2] => hello
            
    )

        [
    Availability] => Array
            (
                [
    0] => One Living Room
                
    [1] => Call not for Availability
                
    [2] => hello
            
    )

        [
    Rates] => Array
            (
                [
    0] => Two Bedrooms
                
    [1] => Not Availabile
                
    [2] => Good Bye
            
    )



  7. #7
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
    //looking for the ths
    $file="saveddbtable/bible.htm";
    $contents_of_page = file_get_contents($file);
     
    $dom = new DOMDocument();
    $dom->loadHTML($contents_of_page);
    // Initialize arrays
    $thArray = $tdArray = $array = array();
    // Get all Table Headers and throw them in an array
    $th = $dom->getElementsByTagName('th');
    foreach ( $th as $th ){
    	$thArray[] = $th->nodeValue;
    }
    // count the array for future comparison
    $count = count($thArray);
    /* Example:
    Array(
    [0] => Unit Type
    [1] => Availability
    [2] => Rates
    )
    */
    // Get all the Table Cells, but if it matches the same count as the Table Header array, create a new array row
    $td = $dom->getElementsByTagName('td');
    $i = 0;
    foreach( $td as $td ) {
    	if(count($tdArray[$i]) != $count){//line 101
    		$tdArray[$i][] = $td->nodeValue;
    	}else{
    		$i++;
    		$tdArray[$i][] = $td->nodeValue;
    	}
    	if($i=100){
    		exit;
    	}
    }
    echo '<pre>';
    print_r(array_combine($thArray, $tdArray));
    echo '</pre>';
    Line 101 says:
    Notice: Undefined offset: 0 in ...\create_bible.php on line 101
    I want to add a pagination at $i. Is it a good start? I limited $i at 100 and then exit the loop to test it first.
    Compare bible texts (and other tools):
    TheWheelofGod

  8. #8
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to extract the innerhtml from this table and store into an array. Howcome it's giving the same notice:
    PHP Code:
    $contents_of_page="<table><tr><th>id</th><th>book</th><th>book_spoke</th><th>recordType</th><th>book_title</th><th>chapter</th><th>chapter_spoke</th><th>verse</th><th>verse_spoke</th><th>text_data</th></tr><tr><td>1</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>1</td><td>1</td><td>In the beginning God created the heaven and the earth.</td></tr><tr><td>2</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>2</td><td>2</td><td>And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.</td></tr><tr><td>3</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>3</td><td>3</td><td>And God said, Let there be light: and there was light.</td></tr><tr><td>4</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>4</td><td>4</td><td>And God saw the light, that it was good: and God divided the light from the darkness.</td></tr><tr><td>5</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>5</td><td>5</td><td>And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day.</td></tr><tr><td>6</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>6</td><td>6</td><td>And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters.</td></tr><tr><td>7</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>7</td><td>7</td><td>And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so.</td></tr><tr><td>8</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>8</td><td>8</td><td>And God called the firmament Heaven. And the evening and the morning were the second day.</td></tr><tr><td>9</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>9</td><td>9</td><td>And God said, Let the waters under the heaven be gathered together unto one place, and let the dry land appear: and it was so.</td></tr><tr><td>10</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>10</td><td>10</td><td>And God called the dry land Earth; and the gathering together of the waters called he Seas: and God saw that it was good.</td></tr><tr><td>11</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>11</td><td>11</td><td>And God said, Let the earth bring forth grass, the herb yielding seed, and the fruit tree yielding fruit after his kind, whose seed is in itself, upon the earth: and it was so.</td></tr><tr><td>12</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>12</td><td>12</td><td>And the earth brought forth grass, and herb yielding seed after his kind, and the tree yielding fruit, whose seed was in itself, after his kind: and God saw that it was good.</td></tr><tr><td>13</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>13</td><td>13</td><td>And the evening and the morning were the third day.</td></tr><tr><td>14</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>14</td><td>14</td><td>And God said, Let there be lights in the firmament of the heaven to divide the day from the night; and let them be for signs, and for seasons, and for days, and years:</td></tr><tr><td>15</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>15</td><td>15</td><td>And let them be for lights in the firmament of the heaven to give light upon the earth: and it was so.</td></tr><tr><td>16</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>16</td><td>16</td><td>And God made two great lights; the greater light to rule the day, and the lesser light to rule the night: he made the stars also.</td></tr><tr><td>17</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>17</td><td>17</td><td>And God set them in the firmament of the heaven to give light upon the earth,</td></tr><tr><td>18</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>18</td><td>18</td><td>And to rule over the day and over the night, and to divide the light from the darkness: and God saw that it was good.</td></tr><tr><td>19</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>19</td><td>19</td><td>And the evening and the morning were the fourth day.</td></tr><tr><td>20</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>20</td><td>20</td><td>And God said, Let the waters bring forth abundantly the moving creature that hath life, and fowl that may fly above the earth in the open firmament of heaven.</td></tr><tr><td>21</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>21</td><td>21</td><td>And God created great whales, and every living creature that moveth, which the waters brought forth abundantly, after their kind, and every winged fowl after his kind: and God saw that it was good.</td></tr><tr><td>22</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>22</td><td>22</td><td>And God blessed them, saying, Be fruitful, and multiply, and fill the waters in the seas, and let fowl multiply in the earth.</td></tr><tr><td>23</td><td>1</td><td>1</td><td>gn</td><td>Genesis</td><td>1</td><td>1</td><td>23</td><td>1</td><td>And the evening and the morning were the fifth day.</td></tr></table>";
    $dom = new DOMDocument();
    $dom->loadHTML($contents_of_page);
    // Initialize arrays
    $thArray $tdArray $array = array();
    // Get all Table Headers and throw them in an array
    $th $dom->getElementsByTagName('th');
    foreach ( 
    $th as $th ){
        
    $thArray[] = $th->nodeValue;
    }
    // count the array for future comparison
    $count count($thArray);
    /* Example:
    Array(
    [0] => Unit Type
    [1] => Availability
    [2] => Rates
    )
    */
    // Get all the Table Cells, but if it matches the same count as the Table Header array, create a new array row
    $td $dom->getElementsByTagName('td');
    $i 0;
    foreach( 
    $td as $td ) {
        if(
    count($tdArray[$i]) != $count){
            
    $tdArray[$i][] = $td->nodeValue;
        }else{
            
    $i++;
            
    $tdArray[$i][] = $td->nodeValue;
        }
        if(
    $i=100){
            exit;
        }
    }
    echo 
    '<pre>';
    print_r(array_combine($thArray$tdArray));
    echo 
    '</pre>'
    Compare bible texts (and other tools):
    TheWheelofGod

  9. #9
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about extracting the innerhtml of the following:
    Code:
    <td class="td_bible_text" valign="top"><span class='GkBibleText'>Ἰωσὴφ δὲ ὁ ἀνὴρ αὐτῆς δίκαιος ὢν, καὶ μὴ θέλων αὐτὴν παραδειγματίσαι, ἐβουλήθη λάθρα ἀπολῦσαι αὐτήν </div> 
    		</td>
    Strangely the span tag closes with </div> and not </span>.
    Compare bible texts (and other tools):
    TheWheelofGod

  10. #10
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    730
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How can I get the Greek part in this:
    Code:
    <pre>array(26) {
      [0]=>
      string(85) "<span class="reftext"><a href="http://biblos.com/matthew/1-1.htm"><b>1</b></a></span>"
      [1]=>
      string(197) "Βίβλος γενέσεως Ἰησοῦ Χριστοῦ, υἱοῦ Δαβίδ, υἱοῦ Ἀβραάμ<p>
    <span class="reftext"><a href="http://biblos.com/matthew/1-2.htm"><b>2</b></a></span>"
      [2]=>
      string(315) "Ἀβραὰμ ἐγέννησεν τὸν Ἰσαάκ Ἰσαὰκ δὲ ἐγέννησεν τὸν Ἰακώβ Ἰακὼβ δὲ ἐγέννησεν τὸν Ἰούδαν καὶ τοὺς ἀδελφοὺς αὐτοῦ
    <span class="reftext"><a href="http://biblos.com/matthew/1-3.htm"><b>3</b></a></span>"
      [3]=>
      string(313) "Ἰούδας δὲ ἐγέννησεν τὸν Φάρες καὶ τὸν Ζάρα ἐκ τῆς Θαμάρ Φάρες δὲ ἐγέννησεν τὸν Ἑσρώμ Ἑσρὼμ δὲ ἐγέννησεν τὸν Ἀράμ
    
    <span class="reftext"><a href="http://biblos.com/matthew/1-4.htm"><b>4</b></a></span>"
      [4]=>
      string(284) "Ἀρὰμ δὲ ἐγέννησεν τὸν Ἀμιναδάβ Ἀμιναδὰβ δὲ ἐγέννησεν τὸν Ναασσών Ναασσὼν δὲ ἐγέννησεν τὸν Σαλμών
    <span class="reftext"><a href="http://biblos.com/matthew/1-5.htm"><b>5</b></a></span>"
      [5]=>
      string(312) "Σαλμὼν δὲ ἐγέννησεν τὸν Βοὸζ ἐκ τῆς Ῥαχάβ Βοὸζ δὲ ἐγέννησεν τὸν Ὠβὴδ ἐκ τῆς Ῥούθ Ὠβὴδ δὲ ἐγέννησεν τὸν Ἰεσσαί
    <span class="reftext"><a href="http://biblos.com/matthew/1-6.htm"><b>6</b></a></span>"
      [6]=>
      string(296) "Ἰεσσαὶ δὲ ἐγέννησεν τὸν Δαβὶδ τὸν βασιλέα Δαβὶδ δὲ ὁ βασιλεὺς ἐγέννησεν τὸν Σολομῶντα ἐκ τῆς τοῦ Οὐρίου
    <span class="reftext"><a href="http://biblos.com/matthew/1-7.htm"><b>7</b></a></span>"
      [7]=>
      string(266) "Σολομὼν δὲ ἐγέννησεν τὸν Ῥοβοάμ Ῥοβοὰμ δὲ ἐγέννησεν τὸν Ἀβιά Ἀβιὰ δὲ ἐγέννησεν τὸν Ἀσά
    <span class="reftext"><a href="http://biblos.com/matthew/1-8.htm"><b>8</b></a></span>"
      [8]=>
      string(271) "Ἀσὰ δὲ ἐγέννησεν τὸν Ἰωσαφάτ Ἰωσαφὰτ δὲ ἐγέννησεν τὸν Ἰωράμ Ἰωρὰμ δὲ ἐγέννησεν τὸν Ὀζίαν
    <span class="reftext"><a href="http://biblos.com/matthew/1-9.htm"><b>9</b></a></span>"
      [9]=>
      string(272) "Ὀζίας δὲ ἐγέννησεν τὸν Ἰωαθάμ Ἰωαθὰμ δὲ ἐγέννησεν τὸν Ἀχάζ Ἀχὰζ δὲ ἐγέννησεν τὸν Ἑζεκίαν
    <span class="reftext"><a href="http://biblos.com/matthew/1-10.htm"><b>10</b></a></span>"
      [10]=>
      string(279) "Ἑζεκίας δὲ ἐγέννησεν τὸν Μανασσῆ Μανασσῆς δὲ ἐγέννησεν τὸν Ἀμών Ἀμὼν δὲ ἐγέννησεν τὸν Ἰωσίαν
    <span class="reftext"><a href="http://biblos.com/matthew/1-11.htm"><b>11</b></a></span>"
      [11]=>
      string(267) "Ἰωσίας δὲ ἐγέννησεν τὸν Ἰεχονίαν καὶ τοὺς ἀδελφοὺς αὐτοῦ ἐπὶ τῆς μετοικεσίας Βαβυλῶνος<p>
    
    <span class="reftext"><a href="http://biblos.com/matthew/1-12.htm"><b>12</b></a></span>"
      [12]=>
      string(291) "Μετὰ δὲ τὴν μετοικεσίαν Βαβυλῶνος Ἰεχονίας ἐγέννησεν τὸν Σαλαθιήλ Σαλαθιὴλ δὲ ἐγέννησεν τὸν Ζοροβαβέλ
    <span class="reftext"><a href="http://biblos.com/matthew/1-13.htm"><b>13</b></a></span>"
      [13]=>
      string(290) "Ζοροβαβὲλ δὲ ἐγέννησεν τὸν Ἀβιούδ Ἀβιοὺδ δὲ ἐγέννησεν τὸν Ἐλιακείμ Ἐλιακεὶμ δὲ ἐγέννησεν τὸν Ἀζώρ
    <span class="reftext"><a href="http://biblos.com/matthew/1-14.htm"><b>14</b></a></span>"
      [14]=>
      string(267) "Ἀζὼρ δὲ ἐγέννησεν τὸν Σαδώκ Σαδὼκ δὲ ἐγέννησεν τὸν Ἀχείμ Ἀχεὶμ δὲ ἐγέννησεν τὸν Ἐλιούδ
    <span class="reftext"><a href="http://biblos.com/matthew/1-15.htm"><b>15</b></a></span>"
      [15]=>
      string(280) "Ἐλιοὺδ δὲ ἐγέννησεν τὸν Ἐλεάζαρ Ἐλεάζαρ δὲ ἐγέννησεν τὸν Ματθάν Ματθὰν δὲ ἐγέννησεν τὸν Ἰακώβ
    <span class="reftext"><a href="http://biblos.com/matthew/1-16.htm"><b>16</b></a></span>"
      [16]=>
      string(267) "Ἰακὼβ δὲ ἐγέννησεν τὸν Ἰωσὴφ τὸν ἄνδρα Μαρίας ἐξ ἧς ἐγεννήθη Ἰησοῦς ὁ λεγόμενος Χριστός<p>
    <span class="reftext"><a href="http://biblos.com/matthew/1-17.htm"><b>17</b></a></span>"
      [17]=>
      string(480) "Πᾶσαι οὖν αἱ γενεαὶ ἀπὸ Ἀβραὰμ ἕως Δαβὶδ γενεαὶ δεκατέσσαρες καὶ ἀπὸ Δαβὶδ ἕως τῆς μετοικεσίας Βαβυλῶνος γενεαὶ δεκατέσσαρες καὶ ἀπὸ τῆς μετοικεσίας Βαβυλῶνος ἕως τοῦ Χριστοῦ γενεαὶ δεκατέσσαρες<p>
    <span class="reftext"><a href="http://biblos.com/matthew/1-18.htm"><b>18</b></a></span>"
      [18]=>
      string(408) "Τοῦ δὲ Ἰησοῦ Χριστοῦ ἡ γέννησις οὕτως ἠν μνηστευθείσης γὰρ τῆς μητρὸς αὐτοῦ Μαρίας τῷ Ἰωσήφ, πρὶν ἢ συνελθεῖν αὐτούς, εὑρέθη ἐν γαστρὶ ἔχουσα ἐκ πνεύματος ἁγίου
    <span class="reftext"><a href="http://biblos.com/matthew/1-19.htm"><b>19</b></a></span>"
      [19]=>
      string(287) "Ἰωσὴφ δὲ ὁ ἀνὴρ αὐτῆς δίκαιος ὢν καὶ μὴ θέλων αὐτὴν παραδειγματίσαι, ἐβουλήθη λάθρᾳ ἀπολῦσαι αὐτήν
    
    <span class="reftext"><a href="http://biblos.com/matthew/1-20.htm"><b>20</b></a></span>"
      [20]=>
      string(463) "ταῦτα δὲ αὐτοῦ ἐνθυμηθέντος ἰδού, ἄγγελος κυρίου κατ' ὄναρ ἐφάνη αὐτῷ λέγων, Ἰωσὴφ υἱὸς Δαβίδ, μὴ φοβηθῇς παραλαβεῖν Μαριὰμ τὴν γυναῖκά σου τὸ γὰρ ἐν αὐτῇ γεννηθὲν ἐκ πνεύματός ἐστιν ἁγίου
    <span class="reftext"><a href="http://biblos.com/matthew/1-21.htm"><b>21</b></a></span>"
      [21]=>
      string(305) "τέξεται δὲ υἱὸν καὶ καλέσεις τὸ ὄνομα αὐτοῦ Ἰησοῦν αὐτὸς γὰρ σώσει τὸν λαὸν αὐτοῦ ἀπὸ τῶν ἁμαρτιῶν αὐτῶν
    <span class="reftext"><a href="http://biblos.com/matthew/1-22.htm"><b>22</b></a></span>"
      [22]=>
      string(255) "Τοῦτο δὲ ὅλον γέγονεν ἵνα πληρωθῇ τὸ ῥηθὲν ὑπὸ τοῦ κυρίου διὰ τοῦ προφήτου λέγοντος,
    <span class="reftext"><a href="http://biblos.com/matthew/1-23.htm"><b>23</b></a></span>"
      [23]=>
      string(347) "Ἰδού, ἡ παρθένος ἐν γαστρὶ ἕξει καὶ τέξεται υἱόν, καὶ καλέσουσιν τὸ ὄνομα αὐτοῦ Ἐμμανουήλ, ὅ ἐστιν μεθερμηνευόμενον, Μεθ' ἡμῶν ὁ θεός
    <span class="reftext"><a href="http://biblos.com/matthew/1-24.htm"><b>24</b></a></span>"
      [24]=>
      string(315) "διεγερθεὶς δὲ ὁ Ἰωσὴφ ἀπὸ τοῦ ὕπνου ἐποίησεν ὡς προσέταξεν αὐτῷ ὁ ἄγγελος κυρίου καὶ παρέλαβεν τὴν γυναῖκα αὐτοῦ
    <span class="reftext"><a href="http://biblos.com/matthew/1-25.htm"><b>25</b></a></span>"
      [25]=>
      string(214) "καὶ οὐκ ἐγίνωσκεν αὐτὴν ἕως οὗ ἔτεκεν τὸν υἱὸν αὐτῆς τὸν πρωτότοκον καὶ ἐκάλεσεν τὸ ὄνομα αὐτοῦ Ἰησοῦν<p>"
    }
    </pre>
    Compare bible texts (and other tools):
    TheWheelofGod


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •