我上传了一个文件,说'example.csv'...如何使用 php 将"示例"存储在变量中,以便在数据库中创建一个表名为"示例"的表?
一种方法是使用pathinfo()
:
http://php.net/pathinfo
$filename = "example.csv";
$dbname = pathinfo($filename, PATHINFO_FILENAME); // $dbname is now "example"
$filename = "example.csv";
//Find the position of the last occurrence of "."
$point_pos = strrpos($filename,".");
//the second argument of substr is the length of the substring
$target = substr($filename, 0, $point_pos);
另一种方法是使用 basename()
函数:
<?php
// your file
$file = 'example.csv';
$info = pathinfo($file);
$file_name = basename($file,'.'.$info['extension']);
echo $file_name; // outputs 'example'
?>