html - How to remove filename from a url in php -


this question has answer here:

i need write php function remove file name inside url. [i don't want remove last part of url. because url's http://www.examples.com/sample "sample" cannot file. want remove file name.

in. -> http://www.inforge.in/ongoing-works/main_project/index.html   out -> http://www.inforge.in/ongoing-works/main_project/  in. -> http://www.inforge.in/ongoing-works/main_project/ out -> http://www.inforge.in/ongoing-works/main_project/  in. -> http://www.inforge.in/ongoing-works/main_project out -> http://www.inforge.in/ongoing-works/main_project/ 

i think solution check whether '.' [dot] present after last '/'. if so, remove after last '/'. didn't logic write in php

i can't check if there exists '.html', because file name can .php, .jpg, .jsp or that

function stripfile($in){     $pieces = explode("/", $in); // split url /     if(count($pieces) < 4) return $in . "/";     if(strpos(end($pieces), ".") !== false){ // got filename @ end         array_pop($pieces); // remove filename     }elseif(end($pieces) !== ""){ // ends name without extension, i.e. directory         $pieces[] = ""; // when $pieces imploded, "/" , "" appended     }     // else, ends slash     return implode("/", $pieces); } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -