[PHP] ファイル名から拡張子を取り除く関数

2006年11月29日 水曜日 22時11分
E-Mail This Post/Page Print This Post/Page

basename() を使ってファイル名を取得した後、もし渡されたファイルの拡張子が一定でない場合、拡張子を除いたファイル名を取得するのに困ることがあります。

そこで、Anton Zamov氏の書かれた以下のカスタム関数を使用するとどのような拡張子でも取り除いてくれるので便利です。

PHP:
  1. function RemoveExtension($strName) 
  2. { 
  3.      $ext = strrchr($strName, '.')
  4.      if($ext !== false) 
  5.      { 
  6.          $strName = substr($strName, 0, -strlen($ext))
  7.      } 
  8.      return $strName
  9. }

使用方法は

PHP:
  1. $Name = 'file.txt'
  2. echo RemoveExtension($filename);

"file" がアウトプットされます。

参考URL:
http://zamov.online.fr/EXHTML/......PHP13.html

この記事に関連するトピック

このエントリーへの Yahoogle Suggestions

Trackback this Post | Feed on comments to this Post

 

記事ヒット TOP 10

IT 関連 NEWS

    There is no entries available for this category.

PHP関連 NEWS

    There is no entries available for this category.

PHP Tips from Social Bookmarks

    There is no entries available for this category.

PHPに関するフォーラムトピック

    There is no entries available for this category.

Tag Cloud

admin Admin Drop Menus Admin Memo Admin Panel advanced drop menus array unique blog cron dabeya Dagon Design Sitemap Generator dropcap Edit N Place error Feedburner game google hack html HTML CSS Internet NEWS Permalink Redirect PHP phpBB2 plugin RSS scripts search stattraq template the content Ultimate Tag Warrior Web Management Windows XP Wordpress WP Plugins WPページ  拡張子 カスタマイズ カスタム関数 カテゴリー コード セキュリティ タグ トップページ トラックバック フィード 投稿 抜粋 日本語 時刻 時間 正規表現 表示 記事

サイト メニュー

Blogtimes image
ぱそずき :D)‐く © 2008
Close
E-mail It