Php Tutorial: External link code functions in regular strings
Function deleteemptyarray ($ val)
{
$ Links = '';
If (is_array ($ val ))
{
Foreach ($ val as $ v =>$ _ v)
{
If (! Empty ($ _ v [0])
{
$ Links. = $ _ v [0]. '| ';
}
}
Return substr ($ links, 0,-1 );
}
Else
{
Return false;
}
}
Function getoutlink ($ body)
{
$ Tempcontent = $ body;
Preg_match_all ("/<(.*?) Href = (.*?) </A>/I ", $ tempcontent, $ tempurl );
$ Urls = array ();
Foreach ($ tempurl [0] as $ value)
{
If (strstr ($ value, 'HTTP '))
{
If (stristr ($ value, $ localurl ))
{
Continue;
}
Else
{
Preg_match_all ("/hrefs * = s * (['"]?) (.*?) 1/is ", $ value, $ vlink );
$ Urls [] = $ vlink [2];
}
}
}
// Print_r ($ urls );
$ Strurl = explode ('|', deleteemptyarray ($ urls ));
$ Tempcount = array_unique ($ strurl );
Echo '& nbsp; external link'. count ($ tempcount)-1;
}
// Call Method
$ Body = "<a href =/AB .htm> aaa </a> <a href = http://www.bkjia.com> I am an external connection </a> ";
Echo getoutlink ($ body );