在PHP中,可以使用http_build_query()
函数来将参数数组转换为URL参数字符串,然后将其附加到URL中。
例如,假设要将以下参数添加到URL中:
$params = array(
'name' => 'John Doe',
'age' => 30,
'city' => 'New York'
);
可以使用以下代码将参数添加到URL中:
$url = 'http://example.com/?' . http_build_query($params);
这将生成以下URL:
http://example.com/?name=John+Doe&age=30&city=New+York
请注意,http_build_query()
函数将空格转换为+
符号。如果要将空格转换为%20
,可以将第二个参数设置为''
,如下所示:
$url = 'http://example.com/?' . http_build_query($params, '', '&');
这将生成以下URL:
http://example.com/?name=John%20Doe&age=30&city=New%20York
下一篇:php 中execute
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站