Hi All I have a field which contain data with spaces .these spaces are long and are mostly in between words. How can I eliminate these spaces and get data in a sentence with only single spaces. Thanks
Not sure if you want spaces at all, so yeah.. This gets rid of all spaces. $spaces = array(" ", " "); $text = "Hello World Hello Again "; $text = str_replace($spaces, "", $text); Code (php):
hi thank you both for your help. $text = preg_replace('~\s{2,}~', ' ', $text); --worked perfect. one more question... i have a string i want to extract a particular value from it (location).there are too many similar symbols in the string so i am not able to do it in the usual way. But if taken from the back i can easily extract the location value.. but don't have any idea how to do it... --------------------------------- this is the string:front street Unique historical building Office Space - 1925 square foot + Call 416-485-9323 (18 Nov 2007) (416) 4859323, - Toronto, ON Mount Pleasant West 3 I want to extract "Toronto, ON Mount Pleasant West 3" from it ------------------------ is there an easy code for it
$location = trim(end(explode('-', $string))); PHP: trim() does only remove spaces from the beginning and end of the string, and not in between.