duanpaotian2348 2016-01-04 07:05
浏览 41
已采纳

如何在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);
}
  • 写回答

1条回答 默认 最新

  • douzhuan1467 2016-01-04 07:09
    关注

    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));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化