RE: [PHP] remove spaces using php function
Well, you can make your own function to to that: ?php function repairString($input) { $string = NULL; $iTmp=explode( ,$input); foreach($iTmp as $word) { if($word!=) $string.=$word ; } return trim($string); } print repairString(this is atest ); // prints this is a test ? Javier Tacón -Mensaje original- De: Uma Shankari T. [mailto:[EMAIL PROTECTED] Enviado el: martes, 07 de octubre de 2003 11:15 Para: PHP Asunto: [PHP] remove spaces using php function Importancia: Baja Hello, Is there any function which will remove extra spaces between each words..?? for example if the user typed asked his friend.. is there any function to remove the extra space between his and asked except one space ?? Regards, Uma -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] remove spaces using php function
Or this one works too :) ?php function repairString($input) { while(($ninput=ereg_replace( , ,$input))!=$input) { $input = $ninput; } return trim($ninput); } print repairString(this is atest ); // prints this is a test ? Javier Tacón. -Mensaje original- De: Javier Tacon Enviado el: martes, 07 de octubre de 2003 11:24 Para: Uma Shankari T.; PHP Asunto: RE: [PHP] remove spaces using php function Importancia: Baja Well, you can make your own function to to that: ?php function repairString($input) { $string = NULL; $iTmp=explode( ,$input); foreach($iTmp as $word) { if($word!=) $string.=$word ; } return trim($string); } print repairString(this is atest ); // prints this is a test ? Javier Tacón -Mensaje original- De: Uma Shankari T. [mailto:[EMAIL PROTECTED] Enviado el: martes, 07 de octubre de 2003 11:15 Para: PHP Asunto: [PHP] remove spaces using php function Importancia: Baja Hello, Is there any function which will remove extra spaces between each words..?? for example if the user typed asked his friend.. is there any function to remove the extra space between his and asked except one space ?? Regards, Uma -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] remove spaces using php function
You mean something like ereg_replace(' +', ' ', 'asked his friend..'); or perhaps preg_replace('/ +/', ' ', 'asked his friend..'); ? Of course, if you're getting this data from a luser, those may not be spaces. They could be obscure, non-printing characters. Take a look at bin2hex to find out. On Tuesday 07 October 2003 02:15 am, Uma Shankari T. wrote: Hello, Is there any function which will remove extra spaces between each words..?? for example if the user typed asked his friend.. is there any function to remove the extra space between his and asked except one space ?? Regards, Uma -- Evan Nemerson [EMAIL PROTECTED] -- Truth, like gold, is to be obtained not by its growth, but by washing away from it all that is not gold. -Leo Nikolaevich Tolstoy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] remove spaces using php function
FYI, preg_replace /should/ be the fastest of all these methods (including Javier's). On Tuesday 07 October 2003 02:25 am, Evan Nemerson wrote: You mean something like ereg_replace(' +', ' ', 'asked his friend..'); or perhaps preg_replace('/ +/', ' ', 'asked his friend..'); ? Of course, if you're getting this data from a luser, those may not be spaces. They could be obscure, non-printing characters. Take a look at bin2hex to find out. On Tuesday 07 October 2003 02:15 am, Uma Shankari T. wrote: Hello, Is there any function which will remove extra spaces between each words..?? for example if the user typed asked his friend.. is there any function to remove the extra space between his and asked except one space ?? Regards, Uma -- Evan Nemerson [EMAIL PROTECTED] -- If anyone can show me, and prove to me, that I am wrong in thought or deed, I will gladly change. I seek the truth, which never yet hurt anybody. It is only persistence in self-delusion and ignorance which does harm. -Marcus Aurelius -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php