Let me share with you one of my small development demos.

I have written a php code that checks in a web page, how many internal and external links it is holding. The code is really easy to install in your site or blog.

I think the SEOs who have a lesser knowldge in php would be very happy to avail this code.

Please check the demo over here.

I am sharing the code below with you :

<h2>External Internal Link checker</h2>
<form action=”” method=”post” enctype=”application/x-www-form-urlencoded” name=”form1″>
<b>Enter Url</b> :
<input name=”url” type=”text” size=”50″ style=”border:1px solid blue;”/>
<input name=”submit” type=”submit” value=”submit” style=”color:black; font-weight:bold; background-color:white; border:0px;” />
</form>
<?php
// retrieve link destinations
function get_a_href($url){
$url = htmlentities(strip_tags($url));
$ExplodeUrlInArray = explode(‘/’,$url);
$DomainName = $ExplodeUrlInArray[2];
$file = file_get_contents($url);
$h1count = preg_match_all(‘/(href=[“|\’])(.*?)([“|\’])/i’,$file,$patterns);
$linksInArray = $patterns[2];
$CountOfLinks = count($linksInArray);
$InternalLinkCount = 0;
$ExternalLinkCount = 0;
for($Counter=0;$Counter<$CountOfLinks;$Counter++)
{

if($linksInArray[$Counter] == “” || $linksInArray[$Counter] == “#”)
continue;
preg_match(‘/javascript:/’, $linksInArray[$Counter],$CheckJavascriptLink);
if($CheckJavascriptLink != NULL)
continue;
$Link = $linksInArray[$Counter];
preg_match(‘/\?/’, $linksInArray[$Counter],$CheckForArgumentsInUrl);
if($CheckForArgumentsInUrl != NULL)
{
$ExplodeLink = explode(‘?’,$linksInArray[$Counter]);
$Link = $ExplodeLink[0];
}
preg_match(‘/’.$DomainName.’/’,$Link,$Check);
if($Check == NULL)
{
preg_match(‘/http:\/\//’,$Link,$ExternalLinkCheck);
if($ExternalLinkCheck == NULL)
{
$InternalDomainsInArray[$InternalLinkCount] = $Link;
$InternalLinkCount++;
}
else
{
$ExternalDomainsInArray[$ExternalLinkCount] = $Link;
$ExternalLinkCount++;
}

}
else
{
$InternalDomainsInArray[$InternalLinkCount] = $Link;
$InternalLinkCount++;
}
}

$LinksResultsInArray = array(
‘ExternalLinks’=>$ExternalDomainsInArray,
‘InternalLinks’=>$InternalDomainsInArray
);
return $LinksResultsInArray;
}

if(isset($_POST[‘submit’]) && $_POST[‘submit’] == ‘submit’)
{

$url = $_POST[‘url’];
$linksInArray = get_a_href($url);
$CountOfExternalLink = count($linksInArray[‘ExternalLinks’]);
$CountOfInternalLink = count($linksInArray[‘InternalLinks’]);
echo “<h1>Link structure</h1>”;

if(!empty($linksInArray[‘ExternalLinks’])){
echo “<br/>External Links found: (“.$CountOfExternalLink.”)<ul>”;
foreach($linksInArray[‘ExternalLinks’] as $key => $val){
$val = preg_replace(“/</”,”<“,$val);
echo “<li>” . htmlentities($val) . “</li>”;
}
echo “</ul>”;
}else{
echo “<br/><div class=\”error\”>No External Links found</div><br/>”;
}

if(!empty($linksInArray[‘InternalLinks’])){
echo “<br/>Internal Links found: (“.$CountOfInternalLink.”)<ul>”;
foreach($linksInArray[‘InternalLinks’] as $key => $val){
$val = preg_replace(“/</”,”<“,$val);
echo “<li>” . htmlentities($val) . “</li>”;
}
echo “</ul>”;
}else{
echo “<br/><div class=\”error\”>No Internal Links found</div><br/>”;
}
}
?>

2 thoughts on “Know your site’s external and internal links!”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.