0
I don’t recommend you do this, for the urlencode
is made to ensure interoperability between the browser and the application, and the correct decoding depends on the characters being properly encoded (otherwise neither would be necessary urlencode
).
Anyway, this will only cause problems, and when recovering the value by PHP application, will not be returned what you are waiting for.
But if that’s what you want, follow a way to change the URL:
$url = str_replace( '%7C', '|', $url );
$url = str_replace( '+', '-', $url );
$url = str_replace( '%2B', '+', $url );
See the result running as requested on IDEONE
Alternative syntax:
$de = array( '%7C', '+', '%2B' ); // acrescente todos os
$para = array( '|' , '-', '+' ); // pares que quiser trocar
$url = str_replace( $de, $para, $url );
Function:
function leonardo_encode( $url ) {
$de = array( '%7C', '+', '%2B' );
$para = array( '|' , '-', '+' );
return str_replace( $de, $para, urlencode( $url ) );
}
rawurlencode
vs urlencode
Important to consider that for what you are doing, the rawurlencode
would be more appropriate than the urlencode
.
urlencode
usually uses it when you’re messing with the query string, or post values:http://example.com/recurso?nome=dados+codificados ^^^^^^^^^^^^^^^^^
rawurlencode
usually used when you are messing with the path/name of the URL resource:http://example.com/recurso/dados%20codificados ^^^^^^^^^^^^^^^^^^^
I’m wearing it, but it brings me this way to
url
like img and I did not want so would like something as specified below img– Leonardo Costa
In my understanding, the question is out of scope for asking for a technically unviable solution, and that is not able to work in practice, nor to be taken advantage of by another user.
– Bacco