Jump to content

help with first function


niche
 Share

Recommended Posts

I'd like to turn this into a function to reduce multiple spaces to one space between characters:

$var = trim($var);//echo $var;while (strpos($var,"  ") > 0) {  $var = str_replace("  "," ",$var);}  

How do I make this into a function?Thanks

Link to comment
Share on other sites

something like this:

function strip_white_space($var) {$var = trim($var);while (strpos($var,"  ") > 0) {  $var = str_replace("  "," ",$var);return $var;} }

Link to comment
Share on other sites

Where do I place the function in the script (presumably it has to be inserted before I can use it)?

Link to comment
Share on other sites

Where do I place the function in the script (presumably it has to be inserted before I can use it)?
You can put it wherever you want it, as long as you declare it within the scope in which you need it. I typically keep my functions near the top of my scripts.
Link to comment
Share on other sites

I understand.Many thanks to chibineku, jkloth, and Deirdre's Dad.Niche

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...