preg_replace";。php;?
如何从字符串结尾处preg_replace.phppreg_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
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;
}