php - Remove specific segment from a URL -
i using codeigniter 2.xx, , view code:
<a href="users/user_info/<?=$row->user_name;?>/<?php echo $row->user_id;?>"></a> and controller code:
function user_info($name, $id) { $info['info'] = $this->user_model->user_info($id); $data['content'] = $this->load->view('home',$info,true); $this->load->view('template',$data); } when click on link url: http://localhost/users/user_info/name/id
i want remove last id segment url becomes: http://localhost/users/user_info/name. how can this? read uri segment doesn't solve question.
if you're trying current url , remove /id it, simply:
$url = $_server["request_uri"]; $paths = explode('/', trim(parse_url($url, php_url_path), '/')); unset($paths[count($paths)-1]); $new_url = '/' . implode('/', $paths); echo $new_url; which removes last url segment, outputting /users/user_info/name if visiting page /users/user_info/name/id
alternatively, change $url string in href="...", again couldn't remove code directly href?
Comments
Post a Comment