Full On Design

Berkshire Based Web Development

 

Checking for embarrassing words in a string

Rogem

About the Author

Mike Rogers is a Web Developer who is currently at University studying Web Technologies. He also is the founder of Full On Design. He has several years experience freelancing and you can follow him on Twitter (Rogem002).

I was recently on YouTube and I noticed that did not check the shortened strings for potentially embarrassing shortenings of words.

YouTube's Cock UpHow to make a great example?

Here is the code so you can shorten strings and check for potentially embrassing words.

<?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
?>
  • Delicious
  • Facebook
  • Digg
  • Reddit
  • StumbleUpon
  • Twitter

Leave a Reply