I would like to be able to escape the character ? which can be included in the message variable of the php string I have seen the jquery escape function
var mensaje = $("#mensajeM").val(); //Hola?
mensaje = escape(mensaje);
in php
$mensaje = $_POST['mensaje']; //Recibo la variable ya con funcion escape
//En la cadena meto la variable mensaje que puede contener el ? ya escapado
$url="http://s/ApiRest_dat/v1/_process/alta?param%5Basunto%5D=".$asunto."¶m%5Bcontenido%5D=".$mensaje."¶m%5Bdestinatarios%5D=".$destinatarios."¶m%5Btoken%5D=".$token."&api_key=".$apiKey;
$json = file_get_contents($url);
$obj = json_decode($json);
echo json_encode($obj);
If the character to be escaped is a white space, it changes it to %20 in the php string and everything is fine, but if the character to be escaped is a ? It doesn't do it right. It gives an error, when doing an echo on $url, the "?" I exchange it for %3F
You can use the function (from pure JavaScript , you don't need
JQuery
)encodeURIComponent( )
: