I am trying to check whether a particular URL is present in a page supplied by another website.
I need to check whether or not the given URL contains a link to my website.
I am using PHP, and I would like to use preg.
I am trying to check whether a particular URL is present in a page supplied by another website.
I need to check whether or not the given URL contains a link to my website.
I am using PHP, and I would like to use preg.
If you know the url you are looking for, can't you use strpos()
?
if (strpos($your_html_page, 'your_url') !== false) {
echo 'The web web page has your_url in it.';
}
This is a simple match - but it doesn't tell you whether it's a hyperlink - just if the url is somwehere in the page. If you want to verify is actually a hyperlink than this approach or a simple regex is not going to help (at least a regex is likely to be fiddly and unreliable). You need to parse the DOM properly, extract out the <a>
elements and check against the href attribute.