Skip to content

Instantly share code, notes, and snippets.

@MikeRogers0
Created June 16, 2012 15:59
Show Gist options
  • Save MikeRogers0/2941771 to your computer and use it in GitHub Desktop.
Save MikeRogers0/2941771 to your computer and use it in GitHub Desktop.
Checking for embarrassing words in a string
<?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