日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php清理html table样式,Parse HTML Table - PHP [closed]

發布時間:2024/7/19 php 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php清理html table样式,Parse HTML Table - PHP [closed] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 6 years ago.

I have an HTML table that I would like to parse in PHP to store into a MySQL Database. The HTML looks like this:

DATELOCATIONNAME

I would like to create a PHP function that returns in an array, the fields in capital letters. Does anyone know any php libraries that can do this, or should I be using a different language, as this may be complex. I don't know exactly how to do this with many tables on the page, but I am trying to parse the VEX events on RobotEvents. The table that I want to parse starts at line 465.

回答1:

As you're prepared to look beyond PHP, Nokogiri (Ruby) and Beautiful Soup (Python) are well-established libraries that parse HTML very well.

That doesn't imply that there are no suitable PHP libraries.

回答2:

Take a look at the PHP HTML DOM Parser library.

To use, you can do something similar to this (not my example):

require('simple_html_dom.php');

$table = array();

$html = file_get_html('http://flow935.com/playlist/flowhis.HTM');

foreach($html->find('tr') as $row) {

$time = $row->find('td',0)->plaintext;

$artist = $row->find('td',1)->plaintext;

$title = $row->find('td',2)->plaintext;

$table[$artist][$title] = true;

}

echo '

';

print_r($table);

echo '

';

There's some tutorials, SO questions and interesting reads about the library. It seems to be pretty popular.

http://davidwalsh.name/php-notifications

http://net.tutsplus.com/tutorials/php/html-parsing-and-screen-scraping-with-the-simple-html-dom-library/

Looping through a table with Simple HTML DOM

how to print cells of a table with simple html dom

UPDATE FOR FINDING SPECIFIC TABLE IN HTML USING ABOVE LIBRARY

To find a particular table amongst many:

1. By class:

On line 465 of your scraped HTML, the table starts with a class catalog-listing, so:

foreach ($html->find('table[@class="catalog-listing"]')->find('tr') as $row) {

// extract TD data

}

2. By instance (find 2nd table in HTML)

foreach ($html->find('table', 2)->find('tr') as $row) {

// extract TD data

}

來源:https://stackoverflow.com/questions/20724728/parse-html-table-php

總結

以上是生活随笔為你收集整理的php清理html table样式,Parse HTML Table - PHP [closed]的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。