Skip to content
Advertisement

print_r not allowing me to escape []

How can I escape the []? If I execute the following code, it just throws me an error

<?php 
$url = 'http://www.example.com/page/?type=software&sortby=title&sortdirection=asc&Name[]=make%3A%20microsoft'; 
$url_components = parse_url($url); 
parse_str($url_components['query'], $params); 
echo ' The '.print_r($params['Name[]']); 
?>

Advertisement

Answer

The name is just Name and you should use implode to join the pieces back together.

echo ' The '. implode($params['Name']);

This assumes your parameter is always Name[].

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement