Mooticus Mooticus - 3 months ago 30
PHP Question

rawurlencode replace spaces with &

I have a form which is named 'q'. I'm using it for Confluence searching, using the REST API. To get multi-word search working, spaces need to be & symbols. The current code makes spaces +. How can i get spaces replacing themselves with & symbols? I've tried using str_replace, and i can't find much on the internet.

if (isset($_GET['q'])) {
$query = rawurlencode( strip_tags($_GET['q']));
$query = str_replace(' ', '&', $query);
$timestamp = time();
$baseUrl = '';
$url = $baseUrl.'/rest/api/content/search?cql=space=KB%20AND%20type=page%20AND%20title~'.$query;


I'm not sure whether this is the "best" way to do it, but it also sounds like a pretty non-conformist request from Confluence (in terms of RFCs), but:

$query = str_replace('%20', '&', $query); // spaces are %20 after raw encoding