Friday, May 29, 2009

Does php have a built-in string function that converts underscores into spaces?

Does php have a built-in string function that converts underscores into spaces?
Not a function that specially only does that task. However to accomplish that goal is simple. All you need to do is use the function "str_replace", its can be used like this: $newstring = str_replace("_"," ",$oldstring); The function "str_replace" takes three arguments:
  • First is what you want to search for, and be replaced. It is called the "needle".
  • Secondly is the replacement, which is used to replace the needle when it is found.
  • Lastly you supply the "haystack", or the string in which you wish to find the needle(s).
It returns a string with the needles replaced with the replacement. You could even replace them with a blank string, which basically removes the needles from the haystack. You can find more information on this at php.net. http://us3.php.net/manual/en/function.str-replace.php

0 comments: