This is some code from a php file im working with. I need to match ‘domain.com’ but when I enter that it’s not working because it’s parsing a document looking for href tags and i think it needs the http://www. for the match. I tried the below preg match but it didn’t work and my coding isn’t to great any help would be appreciated.
preg_match (“/domain.com/i”);
$match = 'http://www.domain.com';
for($i=0;$i<$documentLinks->length;$i++)
{
$documentLink = $documentLinks->item($i);
if ($documentLink->hasAttribute('href') AND substr(strtolower($documentLink->getAttribute('href')), 0, strlen($match)) == $match)
{
try this:
the regexp is the important part:
start at the beginning of the string, match http or https, then an optional subdomain that may not include forward slashes (so you know you’re still in the domain part), followed by the domain you want to match, then either the start of a path, start of a fragment or the end of the url