Re: link counting
| From: | itoctopus | Date: | Sat, 07 Apr 2007 15:34:19 +0000 |
| Subject: | Re: link counting | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-252199@lists.php.net to get a copy of this message | ||
Use the function is_url (note that I haven't written it) instead to check if
the link is a URL.
Not only your method may count some links twice, but it will count wrong
URLs also.
<a href='www.externaldomainnamehere.com'>External</a> is not a URL that will
take someone externally.
Below is the function is_url
function is_url($url) { return
preg_match('#^http\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $url);}
taken from this link:
http://plurged.com/code.php?id=26
--
itoctopus - http://www.itoctopus.com
"Sebe" <sebastian@dslr.net> wrote in message
news:461644A0.9030009@dslr.net...
> i thought of an idea of counting the number of links to reduce comment
spam.
>
> unfortunately my methods is not reliable, i haven't tested it yet
> though.. anyone have maybe a better solution using some regexp?
>
> $links = array('http://',
> 'https://', 'www.');
>
> $total_links = 0;
> foreach($links as $link)
> {
> $total_links = substr_count($string, $link);
> }
>
> if($total_links > X)
> {
> .....
> }