Ordering 2 variables with alltrim

Hello Lord! 😎

There are 2 variables:

$fio = "          "; $digit = "  66a66  " ;

Is it possible, in some way, to “strain” the variables one character at a time and arrange them?

p.s.

Let’s say in Visual Fox, the alltrim() function is enough, it will remove extra spaces in front, behind and in the middle until the 1st, and also make the first character of the new word capitalized, and all the rest capitalized.

With numbers, the only way I found ordering is on this website. In principle, using this, you can leave only numbers from numbers with letters. But hunting is different.


Answer 1, authority 100%

$fio = preg_replace('/\s+/', ' ', $fio); //    
$fio = trim($fio); //    
$digit = preg_replace('/\D/', '', $digit); //    ...
$digit = (int) trim($digit); // ...   
$fio = explode(' ', $fio); //   
for($i = 0, $fl = sizeof($fio); $i < $fl; ++$i){
    $fio[$i] = strtoupper(substr($fio[$i], 0, 1)) . strtolower(substr($fio[$i], 1)); //    
}
$fio = implode(' ', $fio); //  

Updated 02.08.11


Answer 2

I’m sorry, I don’t know exactly, but, for example, C++ has special functions for this.

#include "algorythm"
using namespace std;
int main(){  
    string s("dbca");  
    sort(s); // s == "abcd"  
}