I do not recommend you do this because urlencode
is done to ensure interoperability between the browser and the application, and correct decoding depends on the characters being properly encoded (otherwise, the urlencode
).
Anyway, this will only cause problems, and when retrieving the value by the PHP application, will not be returned what you are expecting .
But if that's what you want, here is 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 per 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
Note that for what you're doing, rawurlencode
would be more appropriate than urlencode
.
-
urlencode
is usually used when you are dealing with query string , or post values:
http://example.com/recurso?nome=dados+codificados
^^^^^^^^^^^^^^^^^
-
rawurlencode
is usually used when you are messing with the path / resource name of the URL:
http://example.com/recurso/dados%20codificados
^^^^^^^^^^^^^^^^^^^