Jump to content

remove file path from string


c_shelswell

Recommended Posts

Hi

does anyone know how i might remove the file path from a string. I'm guessing i use eregi or something like that just can't figure out how to do it.

say i have [b]"E:\Documents and Settings\The King\Desktop\annaalien.jpg"[/b]

and i want to end up with just [b]"annaalien.jpg"[/b]

the file path will be different each time.

Many thanks
Link to comment
https://forums.phpfreaks.com/topic/29650-remove-file-path-from-string/
Share on other sites

here..
from the manual
[code]
<?php
function GetFileName($file_name)
{
      $newfile = basename($file_name);
      if (strpos($newfile,'\\') !== false)
      {
              $tmp = preg_split("[\\\]",$newfile);
              $newfile = $tmp[count($tmp) - 1];
              return($newfile);
      }
      else
      {
              return($file_name);
      }
}
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.