I have read there’s a way to use regex with xpath in php 5.3+ but I don’t have that version and cannot upgrade for certain reasons.
So what I want to know if there’s a way I can achieve the following using Xpath or should I just stick to regex. I want to be able to check if an HTML document contains/matches some of the following:
-
{Powered by|Script Source:|....} <a href='some-domain.com'>Text 1|Text 2|...</a> [e.g. should match: Powered by <a href='http://wordpress.com'>Wordpress</a> -
<img src='....' alt='img-[0-9]-[a-zA-Z].(jpg|png)'> -
<script src='contains particular script'>
Is there any way to achieve any of the above conditions through an xpath query and while not compromising on speed and efficiency?
Here is a PHP script with Simple HTML DOM:
Example.
I have put the code and result on that page.
The strings/URLs/
srcs can be put in an array.As it cycles through an array, it tests for the link
hrefand content, thescriptsrc, and matches theimgsrcwith a regular expression.