In an application i need to do a special character check for dynamic set of special characters that is taken from db.I have tried the following, but it doesnt work,any help will be appreciated.
$specialCharacters = SystemParameters::model()->findByAttributes(array('sys_param_name' => 'SPLCHR'));
// [\^£$%&*()}{@#~?><>,|=_+¬-]'"; This is the resulting value
$var = addslashes($specialCharacters->sys_param_val);
if (preg_match('/' . $var . '/', $string))
return false;
else
return true;
Use
preg_quoteto quote your special characters like this.Based on the fact, that your result from database is not enclosed with square brackets I suppose you want something like this to match against a single special character in your string: