After 2 attempts (thanks to Stack Overflow) I finally got my regex url to work and blacklist specific things in different ways as I wanted. However, it doesn't work properly, whilst yes; it does blacklist the words and prevent them being entered into the database, it throws up an error:
PHP Warning: preg_match() [function.preg-match]: Unknown modifier '\\' in C:\wamp\www\anonpost\index.php on line 324, referer: http://localhost/anonpost/index.php
And here's my code:
$disallowedWords1 = array(
'offensive','words'
);
foreach ($disallowedWords1 as $word1) {
if (preg_match("/\b$word1\b/i", $entry)) {
die('The word or phrase ' . $word . ' is not allowed...');
}
}
$urlRegex = '(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*';
if (preg_match($urlRegex, $entry)) {
die('The word or phrase ' . $word . ' is not allowed...');
}
I looked at some posts that were similar on the site, they all pretty much made the point that there were no delimiter's, well I have those, so I am really lost as to what it could be. Any help would be appreciated :)
(For an example of the error's, of which there are three [three different preg_match() statements, each only marginally different, mainly the way it finds the text] try posting, it's not a problem, it just makes it look messy: http://aviatex14.co.uk/anonpost/ )
preg_quote
. – Lashanda