如何在codeigniter中用其他东西填充url空格?
I am trying to create a url for search results with input values included in url. Everything is working fine except "blank spaces".
I am getting this at the moment:
localhost/admin/search-results/san diego-01/25/2016-01/27/2016-guest House-7
PS, 'San Diego' & 'Guest House'. I can manually change the value of drop downs by adding '-' in value but I afraid doing so will not query DB. Same goes for location text input.
Controller:
public function custom_search() {
$seg1 = $this->input->post('search[1]');
$seg2 = $this->input->post('search[2]');
$seg3 = $this->input->post('search[3]');
$seg4 = $this->input->post('search[4]');
$seg5 = $this->input->post('search[5]');
$segment_array = $this->input->post('search');
$segments = implode("-", $segment_array);
redirect('search-results/'.$segments);
}
我正在尝试为搜索结果创建一个网址,其中输入值包含在网址中。 一切都工作正常,除了“空格”。 p>
我现在得到这个: p>
localhost / admin / search -results / san diego-01/25 / 2016-01 / 27/2016-guest House-7 p> blockquote>
PS,'San Diego'& '招待所'。 我可以通过在值中添加“ - ”来手动更改下拉值,但我担心这样做不会查询数据库。 位置文本输入也是如此。 p>
控制器: p>
public function custom_search(){ $ seg1 = $ this-> input-> post('search [1]'); $ seg2 = $ this-> input-> post('search [2]'); $ seg3 = $ this-> input- > post('search [3]'); $ seg4 = $ this-> input-> post('search [4]'); $ seg5 = $ this-> input-> post('search [5]'); $ segment_array = $ this-> input-> post('search'); $ segments = implode(“ - ”,$ segment_array); 重定向('搜索结果/'。$段); } code> pre> div>
Try use urlencode
function.
This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.
public function custom_search() {
$seg1 = $this->input->post('search[1]');
$seg2 = $this->input->post('search[2]');
$seg3 = $this->input->post('search[3]');
$seg4 = $this->input->post('search[4]');
$seg5 = $this->input->post('search[5]');
$segment_array = $this->input->post('search');
$segments = implode("-", $segment_array);
redirect('search-results/'.urlencode($segments));
}