Re: i want to parse HTML and insert it into DB

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I advise regular expressions to get the contents between the html tags.

I've created the example below:

*<?

// HTML
$html = '
    <html>
        <head>
            <title>Example</title>
        </head>
        <body>
            <table width="100%" border="0" cellspacing="0" cellpadding="1">
                <tr>
                    <td>Heading 1</td>
                    <td>Heading 2</td>
                    <td>Heading 3</td>
                    <td>Heading 4</td>
                </tr>
                <tr>
                    <td>10a</td>
                    <td>20a</td>
                    <td>30a</td>
                    <td>40a</td>
                </tr>
            </table>
        </body>
    </html>
';

// Grab the content from the html tag
$contentsArray =
preg_split("/<\/?\w+((\s+(\w|\w[\w-]*\w)(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/i",$html);

// Function to filter empty contents from the contentsArray
function tagsContent($var) {
    return (trim($var));
}

// Filtering the contentsArray
$filteredContentsArray = array_filter($contentsArray, "tagsContent");

?>

<pre>
<?
// Only the contents of html tags
print_r($filteredContentsArray);
?>
</pre>*




output:

*Array
(
    [3] => Example
    [9] => Heading 1
    [11] => Heading 2
    [13] => Heading 3
    [15] => Heading 4
    [19] => 10a
    [21] => 20a
    [23] => 30a
    [25] => 40a
)*


Ok?

Leo Santana
Nitrocorpz Design
+55 62 91315144


On Wed, Jan 28, 2009 at 10:29 AM, (¯`?.~ Abdul Qadir ~.?´¯) <
abdulqadirmail@xxxxxxxxx> wrote:

>   i just want the contents to insert into DB
> in example i clear it
>
>
> Best Regards,
> Abdul Qadir
> Web Designer & Developer
> Cell:
> +923335760105
> +923455611619
>
> ________________________________
> From: LuCiaNo - CeTre <web@xxxxxxxxxxxx <web%40cetre.com.br>>
> To: php-objects@xxxxxxxxxxxxxxx <php-objects%40yahoogroups.com>
> Sent: Wednesday, January 28, 2009 4:20:56 AM
> Subject: Re:  i want to parse HTML and insert it into DB
>
>
> Do you want just the content or the complete html ?
>
> []s
>
> (¯`?.~ Abdul Qadir ~.?´¯) wrote:
> >
> > Aslam o
> > Alikum
> >
> > Hy dear all
> > I m in a
> > problem please help me
> > Problem : I
> > want to parse html data and insert it into mysql DB
> > Description
> > : I want to open a html file by using php and then read its data in
> > between html
> > tags and insert
> > the data into DBe.g.
> > <table width="100%" border="0" cellspacing="0" cellpadding="1">
> > <tr>
> > <td>Heading 1</td>
> > <td>Heading 2</td>
> > <td>Heading 3</td>
> > <td>Heading 4</td>
> > </tr>
> > <tr>
> > <td>10a</td>
> > <td>20a</td>
> > <td>30a</td>
> > <td>40a</td>
> > </tr>
> > </table>
> > i want to insert the Heading 1, Heading 2..... and 10a, 20a...... and
> > so on.....
> >
> > if anyone
> > can, then guide me please
> >
>
> ------------------------------------
>
> Are you looking for a PHP job? Join the PHP Professionals directory Now!
> http://www.phpclasses.org/professionals/Yahoo! Groups Links
>
> [Non-text portions of this message have been removed]
>
>  
>


[Non-text portions of this message have been removed]


------------------------------------

Are you looking for a PHP job? Join the PHP Professionals directory Now!
http://www.phpclasses.org/professionals/Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/php-objects/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:php-objects-digest@xxxxxxxxxxxxxxx 
    mailto:php-objects-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux