php - How to pass and get color code value with get request -


i have pass color code query string url. right passing directly not giving me desire output.

$color = "#ff0000"; $name = "test"; $download = "1";  $url = "http://localhost/demo?name=".$name."&color=".$color."&download=".$download." "; 

with above url got below output.

array (     [url] => http://localhost/demo     [name] => test ) 

desire output:

array (     [url] => http://localhost/demo     [name] => test     [color] => #fe8c1a     [download] => 1 ) 

please me 1 best way solve problem.

note: have used urlencode($color). working fine dont know correct or not. tell me if other method better this.

yes, urlencode() works fine:

$url = "http://localhost/demo?name=".$name."&color=".urlencode($color)."&download=".$download." "; 

if want alternative, use http_build_query:

$query_string = http_build_query(array(     'name' => $name,     'color' => $color,     'download' => $download, ));  $url = "http://localhost/demo?{$query_string}"; 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -