如何用其他东西填充 codeigniter 中的 url 空格?

How to fill url blank spaces in codigniter with something else?

我正在尝试为输入值包含在 url 中的搜索结果创建 url。除 "blank spaces".

外,一切正常

我现在收到这个:

localhost/admin/search-results/san diego-01/25/2016-01/27/2016-guest House-7

PS、'San Diego' & 'Guest House'。我可以通过在值中添加“-”来手动更改下拉值,但我担心这样做不会查询数据库。位置文本输入也是如此。

控制器:

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);
}

尝试使用 urlencode 函数。

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));
}