if i wanted to block url links or statements from a content post how do i do this Example. in the text bar someone places in http://www.sitename.com or www.sitename.com or sitename.com mainly this would look for http:// www. .com if it contains this information then it will not allow the post. and or it changes the entire url http://www.sitename.com or www.sitename.com or sitename.com to censored or something.. Can anyone help? Thanks in advance.. TJ
i found this function for you at php.net under preg_match function bigworldhostname($url){ preg_match('@^(?:http://)?([^/]+)@i',$url, $matches); $host = $matches[1]; preg_match('/[^.]+\.[^.]+$/', $host, $usHost); if (strlen($usHost[0])>5){ return $usHost[0]; } else { preg_match('/[^.]+\.[^.]+\.[^.]+$/', $host, $restofWorldHost); return $restofWorldHost[0]; } } PHP:
How about this? I ignored URLs like this: sitename.com Because some people don't put spaces after their sentences, and it wouldn't let them post then if they typed something like looked like an URL. $text = preg_replace('/(((ht|f)tps?:\/\/)|(www\.))([\w-\.]+)\.[a-z]{2,4}[^\r\n\s\t"]*/ie', "str_repeat('*', strlen('$0'))", $text); PHP: If you want to check for only .com domains, you can also do this: if (preg_match('/(https?|ftp|www\.|\.com)/i', $text)) { // Throw error } PHP: I think this was your initial idea, but I like the replacement thing better.
Check out http://us2.php.net/function.parse-url This function breaks up a url into its parts and puts in into an array.