我如何判断文件名是否包含两个或更多点

我正在寻找如何判断文件名是否包含两个或更多点的方法。

例如。45FGG.TESTDOC.MAY12.png, carimage.30.jpg。

那么,如何用它的扩展名存储这个图像呢?


ITMISS
浏览 235回答 2
2回答

拉莫斯之舞

您可以使用正则表达式轻松计算点数:PHPpreg_match_all("/\./", "45FGG.TESTDOC.MAY12.png"); // 3JS"45FGG.TESTDOC.MAY12.png".match(/\./g).length; // 3

神不在的星期二

下面是两个测试用例:$file1 = "hello.jpg";$file2 = "hello.file.jpg";echo "\$file1: " . $file1 . "\n";echo "\$file2: " . $file2 . "\n\n";echo "Position of \$file1's first '.' : " . strpos($file1, '.') . "\n";echo "Position of \$file1's last  '.' : " . strripos($file1, '.') . "\n";echo "Position of \$file2's first '.' : " . strpos($file2, '.') . "\n";echo "Position of \$file2's last  '.' : " . strripos($file2, '.') . "\n\n";if (strpos($file1, '.') != strripos($file1, '.')){    echo "\$file1 has >= 2 dots\n";}else{    echo "\$file1 has 1 dot \n";}if (strpos($file2, '.') != strripos($file2, '.')){    echo "\$file2 has >= 2 dots\n";}else{    echo "\$file2 has 1 dot \n";}输出:$file1: hello.jpg$file2: hello.file.jpgPosition of $file1's first '.' : 5Position of $file1's last  '.' : 5Position of $file2's first '.' : 5Position of $file2's last  '.' : 10$file1 has 1 dot$file2 has >= 2 dots
打开App,查看更多内容
随时随地看视频慕课网APP