// Test data
$input = <<<_DATA_
<li id=xyz>
John Johnson
<sup>1<sup>
","
</li>
_DATA_;
//Create a DOM object
$html = new simple_html_dom();
// Load HTML from a string
$html->load($input);
// >> Long answer
echo "Long answer:<br/>";
// Search all text nodes inside the target node
$search = $html->find('li#xyz text');
// Loop through each node and print it
foreach( $search as $i => $txt ) {
// No need to specify "->plaintext" since the content is already in plain text here
echo "$i => " . $txt->plaintext . "<br/>";
}
// >> Short answer
echo "<hr>";
echo "Short answer:<br/>";
// Specifying the index (0th here) returns the Nth element from the array containing all search results
echo $html->find('li#xyz text', 0)->plaintext;
// Clear DOM object
$html->clear();
unset($html);
How to parse a list using simple html dom
By Thanh Tùng
Posted at tháng 2 17, 2019
SimpleHTML
No comments
About Thanh Tùng
Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: Thanh Tùng
Categories
Blog Archive
-
▼
19
(49)
-
▼
02
(18)
- Image Uploader 5.2.4 - Upload hình lên Imgur, Post...
- Tạo trang upload ảnh sử dụng Imgur API trong PHP
- Cấu hình nâng cao cho CSF để bảo vệ VPS
- Hướng dẫn cài đặt đa phiên bản PHP trên DirectAdmin
- Hướng dẫn tích hợp SSL miễn phí Let’s Encrypt vào ...
- Hướng dẫn cài đặt CSF (Config Server Firewall) trê...
- Hướng dẫn tạo và kích hoạt Swap
- Kiểm tra và mở port VPS trên CentOS
- How to parse a list using simple html dom
- Get Cookies from Php Curl
- Responsive Vertical Image Slider với CSS3 và jQuery
- Hướng dẫn cài đặt directadmin 1.44 null
- Chèn thêm cột, hàng sử dụng javascript
- Làm sao để sử dụng lại trình soạn thảo cũ trên Wor...
- Cách duyệt mảng một chiều, đa chiều trong PHP
- Simple html dom parser table to array
- Cách duyệt mảng một chiều, đa chiều trong PHP
- Xử lý ngày tháng trong PHP
-
▼
02
(18)

0 nhận xét: