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
preg_replace";。php;?_Php_String_Preg Replace - Fatal编程技术网

preg_replace";。php;?

preg_replace";。php;?,php,string,preg-replace,Php,String,Preg Replace,如何从字符串结尾处preg_replace.php for ($x = 0; $x < count($sidebar_links); $x++) { $sidebar[$x] = $x; } preg\u replace('\.php$,'.$sidebar\u链接) 或者,为了避免使用正则表达式: if (substr($sidebar_link, -4) == ".php") $sidebar_link = substr($sidebar_li

如何从字符串结尾处preg_replace.php

for ($x = 0; $x < count($sidebar_links); $x++) {

   $sidebar[$x] = $x;           
}
preg\u replace('\.php$,'.$sidebar\u链接)

或者,为了避免使用正则表达式:

if (substr($sidebar_link, -4) == ".php")
     $sidebar_link = substr($sidebar_link, 0, -4);
preg\u replace('\.php$,'.$sidebar\u链接)

或者,为了避免使用正则表达式:

if (substr($sidebar_link, -4) == ".php")
     $sidebar_link = substr($sidebar_link, 0, -4);
你可以使用简单的

你可以使用简单的


我使用以下代码替换文件扩展名。而不是仅仅替换未设置的数组的最后一个索引

private function changeFileExtension($imagePath, $ext=""){
        $arr = explode(".", $imagePath);
        if(count($arr) > 0)
        {
            $arr[count($arr)-1] = $ext;
            return implode(".", $arr);
        }
        else
            return false;
    }

我使用以下代码替换文件扩展名。而不是仅仅替换未设置的数组的最后一个索引

private function changeFileExtension($imagePath, $ext=""){
        $arr = explode(".", $imagePath);
        if(count($arr) > 0)
        {
            $arr[count($arr)-1] = $ext;
            return implode(".", $arr);
        }
        else
            return false;
    }

您可以使用简单str\u replace您可以使用简单str\u replace
private function changeFileExtension($imagePath, $ext=""){
        $arr = explode(".", $imagePath);
        if(count($arr) > 0)
        {
            $arr[count($arr)-1] = $ext;
            return implode(".", $arr);
        }
        else
            return false;
    }