Forum Moderators: coopster
I have a phpbb2 board, and have a mod to prvent non members to post URLs. This most has stopped spam bots big time, but it is also hurting some valid users, who want to post anything with valid words like .com or .net.
How can I modify this regular expression to check for complete valid URL and not just ".com", ".net " etc.
Thanks for any suggestions.
//-- mod : Active-Member-URLs-Only -----------------------------------------------------
{
if( preg_match("/(http¦\bwww\.¦\.(com¦us¦net¦biz¦info¦org¦ru¦su)\b)/i",$HTTP_POST_VARS['message']) ){
message_die(GENERAL_ERROR, sprintf($lang['url_active_only_message'],intval($board_config['url_post_posts']),intval($board_config['url_post_days'])));
}
}
//-- fin mod : Active-Member-URLs-Only -------------------------------------------------
"/(http¦\bwww\.¦\.(com¦us¦net¦biz¦info¦org¦ru¦su)\b)/i"
<?php
$test = array("http://www.example.com/", "www.example.com", 'example.com', 'example.com?this=that', 'www.example.com/', 'example.com/somedirectory/some_page.html?var=var1&var2=4#fragment');
foreach ($test as $k => $v) {
// PATTERN BELOW
$p = "%(?:http://)?(?:www\.)?[\w\.\?#/&-]+%i";
//
if (preg_match($p, $v)) {
echo "$v - Works<br />\n";
}
else {
echo "$v - Not Working<br />\n";
}
}
?>
[edited by: PHP_Chimp at 1:46 pm (utc) on Dec. 18, 2007]