I'm working with Webservice whose city names are all deformatted, and I'd like to create a function to treat the names evenly. An example is this:
PORTO DE GALINHAS
I would like it to look like this:
Porto de Galinhas
I would have to give an explode in the string handle all variables at once putting everything in lowercase and right after giving a ucfirst
in each word making exceptions of ucfirst
in predefined words like of, of, of ...
I know the process but I do not know how to put it in execution.
I tried something:
$string = "PORTO DE GALINHAS";
$array = explode(' ', $string);
foreach ($array as $ar) {
$dados = strtolower($ar);
$dados .= " ";
// Imprime porto de galinhas
$cidade = trim($dados);
}