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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0