আপনি ফিল্টার করতে চান এমন কিছু খারাপ শব্দের একটি ভাল এমওয়াইএসকিউএল টেবিল পরে (আমি এই থ্রেডের একটি লিঙ্ক দিয়ে শুরু করেছি), আপনি এরকম কিছু করতে পারেন:
$errors = array(); //Initialize error array (I use this with all my PHP form validations)
$SCREENNAME = mysql_real_escape_string($_POST['SCREENNAME']); //Escape the input data to prevent SQL injection when you query the profanity table.
$ProfanityCheckString = strtoupper($SCREENNAME); //Make the input string uppercase (so that 'BaDwOrD' is the same as 'BADWORD'). All your values in the profanity table will need to be UPPERCASE for this to work.
$ProfanityCheckString = preg_replace('/[_-]/','',$ProfanityCheckString); //I allow alphanumeric, underscores, and dashes...nothing else (I control this with PHP form validation). Pull out non-alphanumeric characters so 'B-A-D-W-O-R-D' shows up as 'BADWORD'.
$ProfanityCheckString = preg_replace('/1/','I',$ProfanityCheckString); //Replace common numeric representations of letters so '84DW0RD' shows up as 'BADWORD'.
$ProfanityCheckString = preg_replace('/3/','E',$ProfanityCheckString);
$ProfanityCheckString = preg_replace('/4/','A',$ProfanityCheckString);
$ProfanityCheckString = preg_replace('/5/','S',$ProfanityCheckString);
$ProfanityCheckString = preg_replace('/6/','G',$ProfanityCheckString);
$ProfanityCheckString = preg_replace('/7/','T',$ProfanityCheckString);
$ProfanityCheckString = preg_replace('/8/','B',$ProfanityCheckString);
$ProfanityCheckString = preg_replace('/0/','O',$ProfanityCheckString); //Replace ZERO's with O's (Capital letter o's).
$ProfanityCheckString = preg_replace('/Z/','S',$ProfanityCheckString); //Replace Z's with S's, another common substitution. Make sure you replace Z's with S's in your profanity database for this to work properly. Same with all the numbers too--having S3X7 in your database won't work, since this code would render that string as 'SEXY'. The profanity table should have the "rendered" version of the bad words.
$CheckProfanity = mysql_query("SELECT * FROM DATABASE.TABLE p WHERE p.WORD = '".$ProfanityCheckString."'");
if(mysql_num_rows($CheckProfanity) > 0) {$errors[] = 'Please select another Screen Name.';} //Check your profanity table for the scrubbed input. You could get real crazy using LIKE and wildcards, but I only want a simple profanity filter.
if (count($errors) > 0) {foreach($errors as $error) {$errorString .= "<span class='PHPError'>$error</span><br /><br />";} echo $errorString;} //Echo any PHP errors that come out of the validation, including any profanity flagging.
//You can also use these lines to troubleshoot.
//echo $ProfanityCheckString;
//echo "<br />";
//echo mysql_error();
//echo "<br />";
আমি নিশ্চিত যে এই সমস্ত প্রতিস্থাপনের জন্য আরও কার্যকর উপায় আছে তবে আমি এটি নির্ধারণের জন্য যথেষ্ট স্মার্ট নই (এবং এটি অদক্ষভাবে হলেও ঠিকঠাকভাবে কাজ করে বলে মনে হচ্ছে)।
আমি বিশ্বাস করি যে আপনার ব্যবহারকারীদের নিবন্ধন করার অনুমতি দেওয়ার দিক থেকে ভুল হওয়া উচিত, এবং প্রয়োজন অনুসারে আপনার ফিল্টার করার জন্য এবং আপনার অশ্লীল টেবিলটিতে মানব ব্যবহার করা উচিত। যদিও এটি সবগুলি মিথ্যা ধনাত্মক (ভাল শব্দটিকে খারাপ হিসাবে চিহ্নিত করা হয়) বনাম একটি মিথ্যা নেতিবাচক (খারাপ শব্দটি পেয়ে যায়) এর উপর নির্ভর করে। এটি শেষ পর্যন্ত আপনার ফিল্টারিং কৌশলটিতে কতটা আগ্রাসী বা রক্ষণশীল govern
আপনি ওয়াইল্ডকার্ড ব্যবহার করতে চাইলে আমিও খুব সতর্কতা অবলম্বন করব, যেহেতু তারা কখনও কখনও আপনার ইচ্ছার চেয়ে আরও বেশি আচরণ করতে পারে।