I want to use 'fopen' for opening a file and finding a value that is repeated twice in one html file with other functions.
For example , in this page :
<h1> test </h1>
<h1> test </h1>
If i want to get h1 element, i can just get the first one. And the secound one is not accessable . Now , how can we access first and second and maybe next elements?
Simply use file_get_contents() of that file , get those HTML content and pass it to the DOM's loadHTML() and you can finally cycle it up using a loop as shown in the code.
foreach ($dom->getElementsByTagName('h1') as $htag) {
echo $htag->nodeValue;
}
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With