title: PHP preg_replace string path given
body: <p>I have issue with preg_replace function in PHP. I cant figure out a pattern and a replacement.</p>
  
  <p>I have this two strings and some code:</p>
  
  <pre><code>    $dirname1 = 'hdadas/dasdad/dasd/period_1min';
      $dirname2 = 'hdadas/dasdad/dasd/period_1min/abcdrfg.php';
  
      $pieces1 = explode('/', $dirname1);
      $pieces2 = explode('/', $dirname2);
  
      $dirname1 = end($pieces1);  // output will be period_1min
      $dirname2 = end($pieces2); // output will be abcdrfg.php
  
      $output = preg_replace($pattern, $replacement, $dirname1); // or (..,..,$dirname2
  
      echo $output; // i need 1min(without period_) or abcdrfg (without .php)
  </code></pre>
  
  <p><strong>UPD:</strong></p>
  
  <pre><code>   function Cat($dirname)
     {
        $name = explode('/', $dirname);
  
        $pattern = ???;
        $replacement = ???;
  
        return preg_replace($pattern, $replacement, $dirname1);
      }
  
      print(Cat('hdadas/dasdad/dasd/period_1min'))); // output need 1min only
      print(Cat('hdadas/dasdad/dasd/period_1min/abcdrfg.php'))); // output  need abcdrfg only  
  </code></pre>