A website I develop currently have a section that allows users to name things, but I don't want they give any names to anything. So I restrict words which they could use. My current code look like this: $given_name = trim($_POST['given_name']); $reserve = array( ....... "demo" => "demo", "Demo" => "Demo", "example" => "example", "Example" => "Example", ....... ); if (in_array($given_name,$reserve)) { die(msg(0,"[ ".$given_name." ] is unavailable.")); } Code (markup): The list is long and I don't think I will be able to list everything I don't want the users to use. Can I just do it like this, is it valid: $reserve = array( ....... "demo" => "demo", "example" => "example", ....... ); Code (markup): Thank you,
keys should be case sensitive... though I'm not quite sure what the blazes you are setting associative keys for since you're using in_array. Which in_array is case sensitive. Honestly this seems more like a job for a regular expression or stripos. The latter would be ideal as then it's just check for a non boolean false. $reservedWords = [ "demo", "example" ]; foreach ($reservedWords as $word) { if (stripos($given_name, $word) !== false) die('your message here'); } Code (markup):
Thanks for quick response. It comes in time needed. And thanks for suggestion. I'll further study about it.