Autor | Zpráva | ||
---|---|---|---|
Hologos Profil |
#1 · Zasláno: 26. 1. 2011, 16:03:17 · Upravil/a: Hologos
Zdravím,
potřebuji následující a vůbec nevím, jak to napsat elegantně (vím, jak to udělat prasácky, ale třeba to jde jednoduše). Mám jako vstup třeba: show-categories A já potřebuji, aby se mi tento řetězec na showCategories. Můj postup je takový: $result = ''; $pozice = -1; for($i = 0; $i < String::length($input); $i++) { if($input[$i] === '-') $pozice = $i + 1; else { if($i === $pozice) $result .= String::toUpper($input[$i]); else $result .= $input[$i]; } } |
||
Laman Profil |
#2 · Zasláno: 26. 1. 2011, 16:47:28
nevím, jestli je moje řešení skutečně lepší, ale tady jsou 2 návrhy:
$result=str_replace("-"," ",$input); $result=ucwords($result); $result=str_replace(" ","",$result); $result=lcfirst($result); anebo $result=explode("-",$input); for($i=1;$i<count($result);$i++){$result[$i]=ucfirst($result[$i]);} $result=implode("",$result); |
||
Hologos Profil |
#3 · Zasláno: 26. 1. 2011, 20:23:28
Ta první verze se mi lidí, jelikož se dá napsat jako
return lcfirst(str_replace(" ","", ucwords(str_replace("-"," ",$input)))); |
||
Časová prodleva: 13 let
|
0