Tijnema ! wrote:
On 4/7/07, itoctopus <[EMAIL PROTECTED]> wrote:
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

Hmm, it does only take http links, not https,ftp, etc.

Tijnema

I came up with this, not sure if there is a better/faster way but it works for me.
it's case insensitive so you don't have to use strtolower()

preg_match_all('%http://|https://|ftp://%i', $string, $links);
if(count($links[0]) > 2)
{
     // error...
}




--
itoctopus - http://www.itoctopus.com
"Sebe" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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)
> {
>     .....
> }

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to