how to check if an element in an html file exists in another html file? [closed]
Pergunta
Imagine that I have an HTML file as one of my WordPress blog pages (let's call it page B). I want to write an if condition inside a tag on page B to check if a specific element exists on another web page (page A).
My question is what function should I choose to check this condition? Should I also import the HTML file of page A inside page B? And what should I do on the server-side, if I have to?
Thanks
Solução
If I understand you correctly, and you want to find an HTML element inside another page, you need to use some HTML parser.
Take a look at https://www.php.net/manual/en/domdocument.loadhtmlfile.php or https://github.com/paquettg/php-html-parser. I believe there are more tools that can help you with this.
On page B you load page A as a remote document by URL, then parse it and look for the desired HTML element.