将文件名字符限制在 PHP 的中间

Limit a filename character by the middle in PHP

我有一个文件名存储为 25507647_377205372719383_8438629006006905602_n.jpg 并希望它显示为 255076...905602_n.jpg

substr_replace() 获胜。

substr_replace — Replace text within a portion of a string

根据您的设计逻辑,您可以提供正或负的长度参数。

代码:(Demo)

$file = "25507647_377205372719383_8438629006006905602_n.jpg";
echo substr_replace($file, '...', 6, 32);
echo "\n";
echo substr_replace($file, '...', 6, -12);

输出:

255076...905602_n.jpg
255076...905602_n.jpg