So I am working on a project and I need to take a link recovered from a file_get_contents. I got all that taken care of, the problem I am running into is this. The recovered link needs to be a complete link http://www.whatever.com/SomePage.??? I have identified the following types of links can be recovered.
./Page.html
/Page.html
www.somedomain.com
Page.html
http://www.somedomain.com
I have it filtering out http://www.somedomain.com no problem, the same with ./Page.html and /Page.html. On those it rebuilds the entire thing, go that done as well. The problem I am running into is on www.somedomain.com and Page.html. The only way I can figure out how to do this is to check for a top level domain. This is what I got:
elseif (pregmatch('/.AC/i', $link_found) || pregmatch('/.AD/i', $link_found) {
$link_found = "http://".$link_found;
} else {
echo "More code here!";
}
When I run a link like www.somedomain.com the pregmatch picks up the top level and adds the http:// to it. The problem is when I run something like Page.html it does not echo "more code here!" it will run the pregmatch and result in http://Page.html.
I know it is something with the way I am doing this, and that is why I am asking. I need the elseif to match exactly .AU or .COM etc, I have the or for every top level out there. It just keeps picking up the letters or . or something on everything.