Why does not the array value 1 appear in the explode?

4

When I create the code:

$urlAtual = "https://www.meusite.com.br/customer/account/create/";
$parteurl = explode('/', $urlAtual);
    for($i=0;$i<=6;$i++){
        $parteurldesejada = $parteurl[$i] . "<br>";
        echo $parteurldesejada;
    }

It prints in the browser this:

https:

www.meusite.com.br
customer
account
create

Notice that the [1] value of the array is not shown. Why?

Source code looks like this:

<!DOCTYPE html>
<html>
   <head>
      <title>Lucas Carvalho</title>
      <meta charset="UTF-8">
   </head>
   <body>
    https:<br><br>www.meusite.com.br<br>customer<br>account<br>create<br><br></body>
</html>
    
asked by anonymous 17.07.2017 / 19:25

2 answers

8

It is because you are giving explode to / and in // it recognizes that there is an empty value between them.

Apparently what you need to do can be done with the parse_url ()

$urlAtual = "https://www.meusite.com.br/customer/account/create/";
var_dump(parse_url($urlAtual));
    
17.07.2017 / 19:28
3

In the php.net has an example similar to what you do. It recognizes / after / and prints empty

    
17.07.2017 / 19:30