RE: [PHP] Is there any function that sorts the contents of a string?
| From: | Don Read | Date: | Sat, 24 May 2003 19:22:04 +0000 |
| Subject: | RE: [PHP] Is there any function that sorts the contents of a string? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148875@lists.php.net to get a copy of this message | ||
On 24-May-2003 John W. Holmes wrote:
>> Hello, is there any function that will change "acb" to "abc",
>> "rys" to
>> "rsy"
>> and so on? Otherwise, how would I sort them?
>
> Convert your string into an array, sort the array, and then turn it back
> into a string. Or use some sort of sorting algorithm and go letter by
> letter.
>
> $l = strlen($string);
> for($x=0;$x<$l;$x++)
> { $ar[] = $string{$x}; }
$ ar=preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);
...
Regards,
--
Don Read dread@texas.net
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.