Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-如何删除文本并格式化回显字符串?_Php_String - Fatal编程技术网

PHP-如何删除文本并格式化回显字符串?

PHP-如何删除文本并格式化回显字符串?,php,string,Php,String,我有一个名为$file\u path的字符串对于php库,当我为该目录上的所有img文件制作“gallery/png.png”、“gallery/jpg.jpg”、“gallery/gif.gif”等时。我想删除$file\u路径的“gallery/”和“.format” echo basename($file_path,".png"); 将只返回文件名 这是问题的第三个版本,下次请先解决你想问的问题: echo pathinfo($file_path, PATHINFO_FILENAME);

我有一个名为
$file\u path的字符串对于php库,当我为该目录上的所有img文件制作
“gallery/png.png”“gallery/jpg.jpg”“gallery/gif.gif”等时。我想删除
$file\u路径的“gallery/”“.format”

echo basename($file_path,".png");
将只返回文件名

这是问题的第三个版本,下次请先解决你想问的问题:

echo pathinfo($file_path, PATHINFO_FILENAME);
如果
$file\u path
为“gallery/file.jpg”

请尝试此操作,此操作将回显“file”

str_replace('gallery/', '', $file_path);
$url=“gallery/test.png”;
$string=str_split($url);
$phase=0;
美元产出;
对于($i=0;$i

只输出文件名

试试这个,希望它能工作

$file_path = str_replace('gallery/', '', str_replace('.png', '', $file_path) );

编辑答案,请不要继续改变问题@Kake@Kake您可以使用str_replace('.png','$file_path);
$file_path = str_replace('gallery/', '', str_replace('.png', '', $file_path) );