Created
June 16, 2012 15:59
-
-
Save MikeRogers0/2941771 to your computer and use it in GitHub Desktop.
Checking for embarrassing words in a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// String Cleaner – Cleans words you don't want out of strings. | |
// Step 1 – Define the string and the words yoiu want to remove. | |
$string = 'this is my silly input how cool is it?'; | |
$words_to_remove ='silly|my|eggs'; // Seperate words with | this is regular expression. | |
// Step 2 – shorten the string | |
$string = substr($string, 0, 23); // This with return the first 23 characters (including spaces) in the string. | |
// Step 3 – Remove the words | |
echo preg_replace('#b('.$words_to_remove.')b#is', '', $string); // This will remove the | |
// This would return: | |
// this is input | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment