Jump to content

help with first function


niche

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...