Ec (2); php tutorial efficiency string processing method & lt ;? Php $ strarray (& quot; helloworld & quot;, & quot; howareyou & quot;, & quot; cpufrequency & quot;, & quot; windows7ready & quot;, & quot; newedition2 & quot;, & quot; downloadurllist & q script ec (2); script
Php tutorial efficiency string processing method
$ Str = array (
"Helloworld ",
"Howareyou ",
"Cpufrequency ",
"Windows7ready ",
"Newedition2 ",
"Downloadurllist ",
"Heisasuperhero ",
);
// Your solution
/*
After adding spaces correctly, it should be:
"Helloworld" = "hello world"
"Howareyou" = "how are you"
"Cpufrequency" = "cpu frequency"
"Windows7ready" = "windows 7 ready"
"Newedition2" = "new edition 2"
"Downloadurllist" = "download url list"
"Heisasuperhero" = "he is a super hero"
*/
?>
Program code
Function transfer ($ input ){
$ Newarray = array ();
Foreach ($ input as $ I ){
$ Arr = str_split ($ I );
$ Word = '';
Foreach ($ arr as $ ){
$ Ascii = ord ($ );
$ Lastword = substr ($ word,-1 );
$ Ascii_1 = ord ($ lastword );
$ Lastword _ = substr ($ word,-2, 1 );
If ($ ascii> 64 & $ ascii <91 ){
If ($ ascii_1> 96 & $ ascii_1 <122 ){
$ Word. = ''. $;
} Else {
$ Word. = $;
}
} Elseif ($ ascii> 96 & $ ascii <122 ){
If ($ ascii_1> 64 & $ ascii_1 <91 ){
If (strlen ($ word) = 1 ){
$ Word. = $;
} Else {
If (ord ($ lastword _) = 32 ){
$ Word. = $;
} Else {
$ Word = substr ($ word, 0,-1). ''. $ lastword. $;
}
}
} Else {
$ Word. = $;
}
} Else {
If (strlen ($ word) = 0 ){
$ Word. = $;
} Else {
$ Word. = ''. $;
}
}
}
$ Newarray [$ I] = $ word;
}
Return $ newarray;
}
Print_r (transfer ($ str ));