Cybot, try this ....
function string_dryclean($dirtystring) { $cleanstring = str_replace("\n", " ", $dirtystring); $cleanstring = trim(str_replace("\t", " ", $cleanstring)); do { $cleanstring = str_replace(" ", " ", $cleanstring); } while (strpos($cleanstring, " ") > 0); return $cleanstring; } use it like this... $ugly_evil_string = " hello \n\n \n\t world \n\n\t "; $decent_law_abiding_string = string_dryclean($ugly_evil_string); ----- Original Message ----- From: "cybot" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Saturday, February 01, 2003 1:58 AM Subject: Re: [PHP-WIN] Something like trim() > is there no more complicated solution for this? ;-) > > nothing for bad! > > B.A.T. Svensson wrote: > > Something like (not tested and compiled - please find the bugs :)) > > will remove white space dups: > > > > char *TrimInString(char *pzWashMe) > > { > > if (!pzWashMe) return NULL; > > > > register char *pzMarker = pzWashMe; > > bool bStillTrimingString = false; > > > > while (StrReplacee("\t", " ", pzMarkerrReplacee("\n", " ", pzMarker)) > > ;; > > > > while (*pzMarker) { // loop 1 > > bool bStillTrimingString = false; > > > > while (*pzMarker && !isspace(*(pzMarker++)) // loop 2 > > ;; > > > > register int nIndex = 0; > > while (isspace(*(pzMarker+nIndex++)) { // loop 3 > > bStillTrimingString = true; > > } > > > > if (nIndex) { > > strcpy(pzMarker, (pzMarker + nIndex)); > > } > > > > } > > > > return pzMarker; > > > > } > > > > First it replace tabs and newlines with blank spaces, then > > the function will scann the string after a whitespace (loop 2). > > If it finds one. Then it will try to justify the hypothese H that > > this white space is followed by another white space (loop 3). If > > H is true it will count the number of whitepace, and then move > > the moving down data to just leave the first white space left. > > > > After that it falls into loop 1 again and check if we reach the > > end of the string or not, if not, we do all the things once again. > > > > > > > >>-----Original Message----- > >>From: Bobo Wieland [mailto:[EMAIL PROTECTED]] > >>Sent: Thursday, January 30, 2003 8:26 AM > >>To: [EMAIL PROTECTED] > >>Subject: [PHP-WIN] Something like trim() > >> > >> > >>Is there an easy way to get rid off white space characters in a string? Like > >>trim() but for the whole string and leaving single white spaces as they are > >>but removing all occurences of '\t','\n' and ' '(leaving a single ' > >>')... > >> > >>I've tried the manual but couldn't find anything... > >> > >> > >> > >>. bobo . www.elstudion.com . www.elstudion.com/bobo . > >> > >> > >>-- > >>PHP Windows Mailing List (http://www.php.net/) > >>To unsubscribe, visit: http://www.php.net/unsub.php > >> > > -- > Sebastian Mendel > > [EMAIL PROTECTED] > > www.sebastianmendel.de > www.tekkno4u.de > www.nofetish.com > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php