Exchange% 20 for + in search via GET

3

When I do a search via GET through a form the url looks like this:

  

test.txt?

I would like it to look like this:

  

test.blogspot.blogspot.blogspot.com

Does anyone know how to do this? Reference: link

Form Code:

<form class="form-inline" action="busca.php" method="get" >        
        <div class="form-group" style="width:100%">
            <label for="numero" class="control-label">Busca</label><br>
            <input class="form-control" id="termo" name="termo" type="text" value="" style="width:100%">
        </div>
<div class="form-group" style="width:100%">
            <br>
            <button type="submit" class="btn btn-primary" style="width:100%!important; padding:6px 12px;"><i class="fa fa-search" aria-hidden="true"></i> Pesquisar</button>
        </div><!-- /form-group -->
</form>
    
asked by anonymous 14.09.2018 / 21:42

1 answer

6

Both %20 and + are valid characters to represent the space, being the first one used in URLs and the second one in forms, by default (for example in querystring ).

The + was specified in this RFC:

  

link

And then it was replaced with %20 .

In PHP itself, urlencode() uses %20 , and for compatibility purposes, rawurlencode() was maintained with the behavior of RFC 3986.

What defines browser-side submission formatting is enctype , which is not in your original form :

<form enctype="application/x-www-form-urlencoded">

Manual

  

link

It can happen that newer applications use %20 "on the go" (remembering that in a normal form this is done by the browser and not the PHP side). If you really want to use + because you want to leave the link with a different aesthetic, regardless of the browser , you will have to POST to a PHP that gives a redirect using rawurlencode , but I would not recommend casting the application that way.

    
14.09.2018 / 21:52