title: php remove filename from url if exists
body: <p>hello I would like to remove all filenames from my url :</p>
  
  <pre><code>http://website.com/folder1/folder2/filename.php
  </code></pre>
  
  <p>here is what I have tried :</p>
  
  <pre><code>$file_info = pathinfo('http://website.com/folder1/folder2/filename.php');
  echo $file_info['dirname'];
  </code></pre>
  
  <p>outputs <a href="http://website.com/folder1/folder2/" rel="nofollow">http://website.com/folder1/folder2/</a> wich is what I want , but when I try this :</p>
  
  <pre><code>   $file_info = pathinfo('http://website.com/folder1/folder2/');
      echo $file_info['dirname'];
  </code></pre>
  
  <p>it outputs <a href="http://website.com/folder1/" rel="nofollow">http://website.com/folder1/</a>. &nbsp; <br>
  now what I want is if the url contains a filename then it gets removed , and if url has only folders then do nothing .<br>
  (I don't want to use .htaccess for this)</p>