Re: Re: link counting
| From: | Sebe | Date: | Sat, 07 Apr 2007 20:22:26 +0000 |
| Subject: | Re: Re: link counting | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-252214@lists.php.net to get a copy of this message | ||
Tijnema ! wrote:
On 4/7/07, itoctopus <newsgroup@itoctopus.com> wrote: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) {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=26Hmm, it does only take http links, not https,ftp, etc. Tijnema
// error...}
-- 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 commentspam.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