Remove Spaces in PHP Strings

Mon Oct 26 01:07:57 2009

I'm still very much at the beginning of learning PHP and while programming this blog, I came across a wonderful PHP function that can be used to remove/replace spaces (amongst other things) in strings. I know it will come in handy for someone. It's called str_replace(); The syntax is as follows:

str_replace(item to be replaced, item to replace with, string to commit this function);
//creating a string held inside a variable.
$origString = "This is the original string.";
//display the string.
echo $origString;

//replace " " width "". In other words, replace spaces with no spaces.
$newString = str_replace (" ", "", $origString);
//display the new string.
echo $newString;


← back

Most recent posts

  1. Flashcards Maker - the app the helps you learn in a flash
  2. Convert Font Suitcase to TTF in 3 Easy Steps
  3. Rain or Shine - Weather Forecast Available Now!
  4. Getting around Apple's silly rules for iOS 10
  5. Localising App Names for iOS and Android

Search site:

Apps by

Click the app icons to see more info