mercredi 16 décembre 2015

Php If with || not working

    do  {
    if ($dir[$i] == " " || is_numeric($dir[$i])
        {
        $direccion=$direccion.$dir[$i];
        }
    elseif ($i>6)
        {
        $i=strlen($dir)
        }
    }           
while ($i <= count($dir))

$dir is the variable i use to get a google address, but the thing is that it comes with Zip code and City. The thing is that I only need the Street and number.

in the first run $dir = "Calle 30 433B29938 LaPlataBuenosAiresArgentina" And i only need from that 30 433

Since the word " Calle " is always in the return, I've made an if that if its > 6, $i automatically will equal the lenght of the chain and kick me out of the while, because I'll be in "Calle " and there's when the 30 433 begins. The other ifs that I've made, one of them controls if It's a space to add it to the new string $direccion, and the other one checks if It's a number. If it's not a number and if It's not a space and $i > 6, means that I'm in B and I want to finish the do/while.

result of $direccion should be = 30 433. But i get an error on line 3 telling me that there is a problem with a {.

Aucun commentaire:

Enregistrer un commentaire