/* Encode a query parameter value using rawurlencode() */
$keyword = 'iPhone & Galaxy/Note=100% #1';
$encoded = rawurlencode($keyword);

echo 'https://example.com/search?query=' . $encoded;
// Output: 'https://example.com/search?query=iPhone%20%26%20Galaxy%2FNote%3D100%25%20%231'

/* Decode the query parameter using rawurldecode() */
$decoded = rawurldecode($encoded);
echo $decoded;
// Output: 'iPhone & Galaxy/Note=100% #1'
rawurldecode(string $string): string
// Server URL and image path containing spaces and special characters
$server_url = 'https://www.example.com';
$image_path = '/images/my image.jpg';

// Use rawurlencode() when appending file paths to URLs
$encoded_image_path = rawurlencode($image_path);

$image_url = $server_url . $encoded_image_path;

echo $image_url . '<br>';
// Output: 'https://www.example.com%2Fimages%2Fmy%20image.jpg'

$rawurlencode_image_path  = rawurldecode($image_path);
echo $rawurlencode_image_path;
// Output: '/images/my image.jpg'