Tôi đang cố gắng cụm từ nguồn HTML bằng cách sử dụng cụm từ HTML DOM, tôi cần nhận được một giá trị bên trong thẻ đầu vào, tôi đã thử điều này:
foreach [$doc->getElementsByTagName['input'] as $link]
{
$links[] = array[
'value' => $link->getAttribute['value'],
'text' => $link->nodeValue,
];
}
Điều này hoạt động với tôi, nhưng trang web của tôi có nhiều thẻ đầu vào hơn, nhưng tôi muốn nhận được giá trị của thẻ đầu vào được chỉ định.
Giả sử nó,
Tôi đã cố gắng sử dụng getElementsByTagName
, nhưng nó cho tôi một lỗi.
[Php 5, Php 7, Php 8]
DomDocument :: — Searches for all elements with given local tag name
Sự mô tả
PublicDomDocument :: DOMDocument::getElementsByTagName[string $qualifiedName
]:
DOMNodeList
Thông số
qualifiedName
Tên địa phương [không có không gian tên] của thẻ để khớp với. Giá trị đặc biệt *
khớp với tất cả các thẻ.
Trả về giá trị
Một đối tượng Domnodelist mới chứa tất cả các yếu tố phù hợp.DOMNodeList object containing all the matched elements.
Ví dụ
Ví dụ #1 Ví dụ sử dụng cơ bản
Patterns of Enterprise Application Architecture
Design Patterns: Elements of Reusable Software Design
Clean Code
XML;$dom = new DOMDocument;
$dom->loadXML[$xml];
$books = $dom->getElementsByTagName['book'];
foreach [$books as $book] {
echo $book->nodeValue, PHP_EOL;
}
?>
Ví dụ trên sẽ xuất ra:
Patterns of Enterprise Application Architecture Design Patterns: Elements of Reusable Software Design Clean Code
Xem thêm
- DomDocument :: getElementsByTagNamens [] - Tìm kiếm tất cả các yếu tố có tên thẻ đã cho trong không gian tên được chỉ định
James L ¶ ¶
14 năm trước
Return if there are no matches is an empty DOMNodeList. Check using length property, e.g.:
0Philip n ¶ ¶
12 năm trước
1
2
3
0Calvin tại G Mail ¶ ¶
12 năm trước
5
6
7
8Calvin tại G Mail ¶ ¶
gurmukh24 tại gmail dot com ¶
9Patterns of Enterprise Application Architecture Design Patterns: Elements of Reusable Software Design Clean Code0
Patterns of Enterprise Application Architecture Design Patterns: Elements of Reusable Software Design Clean Code1
Patterns of Enterprise Application Architecture Design Patterns: Elements of Reusable Software Design Clean Code2
13 năm trước ¶
đá quý tại rellim dot com ¶
Patterns of Enterprise Application Architecture Design Patterns: Elements of Reusable Software Design Clean Code3
Patterns of Enterprise Application Architecture Design Patterns: Elements of Reusable Software Design Clean Code4
Patterns of Enterprise Application Architecture Design Patterns: Elements of Reusable Software Design Clean Code5
Patterns of Enterprise Application Architecture Design Patterns: Elements of Reusable Software Design Clean Code6
18 năm trước ¶
Yaakov dot moddel tại gmail dot com ¶
Patterns of Enterprise Application Architecture Design Patterns: Elements of Reusable Software Design Clean Code7
Patterns of Enterprise Application Architecture Design Patterns: Elements of Reusable Software Design Clean Code8
010 năm trước ¶
rsvvuuren tại hotmail dot com
getElementsByTagName
0
getElementsByTagName
1
getElementsByTagName
2
getElementsByTagName
3
getElementsByTagName
4
getElementsByTagName
5
getElementsByTagName
6
getElementsByTagName
78 năm trước ¶
Simon tại onepointltd dot com
getElementsByTagName
8
getElementsByTagName
9
$qualifiedName
0
$qualifiedName
19 năm trước ¶
12 năm trước
$qualifiedName
2
$qualifiedName
3
$qualifiedName
4
$qualifiedName
5Calvin tại G Mail ¶ ¶
gurmukh24 tại gmail dot com ¶
$qualifiedName
6
$qualifiedName
7
013 năm trước ¶
12 năm trước
$qualifiedName
9
qualifiedName
0
qualifiedName
1
qualifiedName
2
qualifiedName
3Calvin tại G Mail ¶ ¶
12 năm trước
qualifiedName
4
qualifiedName
5
qualifiedName
6
qualifiedName
7
qualifiedName
8Calvin tại G Mail ¶ ¶
14 năm trước
qualifiedName
9
*
0
*
1
*
2
*
3
0Philip n ¶ ¶
12 năm trước
*
5
*
6
*
7
*
8
0Tôi có thể sử dụng getEuityByid trong PHP không?
Nhận phần tử là gì bởi TagName?
Làm thế nào tôi có thể gọi ID HTML trong PHP?
Làm cách nào để có được một yếu tố trong HTML?
elements with class="intro" .