[PHP] Re: link counting

2007-04-07 Thread itoctopus
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 [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



Re: [PHP] Re: link counting

2007-04-07 Thread Tijnema !

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




--
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



Re: [PHP] Re: link counting

2007-04-07 Thread Sebe

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



[PHP] Re: link counting

2007-04-06 Thread Jonesy
On Fri, 06 Apr 2007 09:01:20 -0400, Sebe wrote:
 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)
 {
 .
 }

What I use:


 function check_bad_content($string)
 {
  // Stuff that spammers post with:
  $bad_strings =  array('www.','/url]','ttp://','ttps://') ;

  foreach( $bad_strings as $bad_string )
  {
   if ( ereg( $bad_string, $string ) ) return false ;
  }

  return true;

 }  // E-O- function check_bad_content


I permit _*NO*_ URL's on my message board.  I guess you could just as 
easily count them in the function above -- versus setting TRUE/FALSE.

Jonesy
-- 
  Marvin L Jones| jonz  | W3DHJ  | linux
   38.24N  104.55W  |  @ config.com | Jonesy |  OS/2
*** Killfiling google posts: http://jonz.net/ng.htm

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