Reply to Re: HTML Table > database entry

Your name:

Reply:


Posted by Christoph Burschka on 04/26/07 20:50

Blagovist wrote:
> Virginner wrote:
>> "Blagovist" <blag@ovist.com> wrote in message
>> news:462f0f0f_3@x-privat.org...
>>> Hi.
>>> Is there an easy way to "lift" data from HTML tables and enter that
>>> into my database? I'm a total novice and so far my searches have
>>> yielded little. I see Navicat has an import option, but that appears
>>> to be for well structured data like Word, Excel or PDF...
>>>
>>> Thanks,
>>>
>>> Blago
>>
>> If you've got Excel, then you can "bounce" a table via that (copy /
>> paste) then use that to import via Navicat....
>>
>> D.
>
> I found something called easywebsave (an IE add-on) that looks
> promising. But still a long way from being automated.
>
> Blaqgo

The following code relies heavily on your input html table being well-formatted
XHTML:

$text = "<table> [your table here] </table>";

/* first, strip the first and last tr tags.
preg_match('/<tr[^>]*>(.+)<\/tr>/',$text,$match);
$to_split=$match[1];

/* now split wherever a row is closed, then opened. */
$rows = preg_split('/<\/td>.*?<\/tr>.*?<tr[^>]*>.*?<td[^>]>/',$to_split);

foreach ($rows as $row)
{
// now split the rows into cells.
$cells[]=preg_split('/<\/td>.*?<td[^>]*>/',$row);
}


Your data is now split in a two-dimensional array. Putting it into a database is
pretty trivial after that.

--
cb

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация