php刪除字元串指定
① php 怎麼樣刪除指定字元串中的指定字元
<?php
$str = "我_們_的_=家+園";
$str = str_replace(array("_","=","+"),"",$str);
echo $str;
?>
② php 刪除含指定字元的文件
<?php
$dir="upload";
delete_file($dir);
functiondelete_file($dir){
$list=scandir($dir);//得到該文件下的所有文件和文件夾
foreach($listas$file){//遍歷
$file_location=$dir."/".$file;//生成路徑
if(is_dir($file_location)&&$file!="."&&$file!=".."){//判斷是不是文件夾
echo"------------------------signin$file_location------------------";
delete_file($file_location);//繼續遍歷
}elseif($file!="."&&$file!=".."){
$str="s";//指定字元串
if(substr_count($file,$str)>0){//如果文件名包含該字元串
unlink($file);
}
}
}
}
③ php刪除最末端指定的字元串,rtrim不能達到預期效果,求大神提供快速簡潔的方法
$str = "I have a dream!";
echo rtrim($str,"!"); // 去除末端的 "!"
就會顯示:I have a dream
你要看下有沒有用對,實在不行試試替換字元串的那個,把不想要的替換成空字元串,暫時想到這些了
④ php刪除字元串中指定字元前的字元
<?php
$str='海南省-海口市-美蘭區';
$str=preg_replace('/^[^-]*-/is','',$str);
echo$str;
exit;
⑤ php中如何刪除一個字元串中的指定字元及其後面的n個字元
簡單的可以實現你的功能,如果是漢字的話可能會有問題,這個沒有測試:
$str="";
functiontusub($str,$flag,$long){
//獲取指定字元串到其後面n個長度後的字元串
$index=strpos($str,$flag);
$tempstr=substr($str,$index,$long+strlen($flag));
//以上面得到的字元串把原字元串分隔成兩個字元串
$index2=strpos($str,$tempstr);
$str1=substr($str,0,$index2);
$str2=substr($str,$index2+strlen($tempstr));
//把一頭一尾兩個字元串拼接好輸出
return$str1.$str2;
}
//刪除字元串$str中GJ開始往後的5個字元串
echotusub($str,'gy',1);
⑥ 如何去掉一個字元串中某個字元 php
用字元串替換就行了,將你想換掉的字元替換為空就可以了。
比如說:
你原來的字元串是
"abcdefg",想將其中的a去掉,則可以用以下方法
$str="abcdefg";
$str=str_replace('a','',$str);
echo
$str;
希望可以幫到你。
⑦ php字元串去掉指定字元
正則可以解決問題,但如果你是用在項目中的話,你就不得不考慮代碼的效率問題,顯然的,正則表達式的效率是很低的,能不用正則就不要用,切記!
就像現在的問題,你可以這么寫:
<?php
$str = "我_們_的_=家+園";
$str = str_replace(array("_","=","+"),"",$str);
echo $str;
?>
⑧ PHP用什麼函數把字元串中的某個字元去掉
用字元串替換就行了,將你想換掉的字元替換為空就可以了。
比如說:
你原來的字元串是
"abcdefg",想將其中的a去掉,則可以用以下方法
$str="abcdefg";
$str=str_replace('a','',$str);
echo
$str;
希望可以幫到你。
⑨ PHP語言:如何刪除字元串中的某個字元串
概括起來兩個方法吧。
方法一
$string = '';
$string = preg_replace('/[abc]+/i','',$string);
方法二
把字元串轉化成數組
$arr = str_split($string);
foreach( $arr as $key => $value ){
if( in_array($value,array('a','b','c')) ){
unset($arr[$key]);
}
}
$string = implode('',$arr);
強烈推薦方法一,方法二不支持字元串中有中文。
⑩ PHP怎麼刪除字元串中的指定字元,高手來幫忙看一下、
刪除第四個參數嗎,示例代碼:
<?php
$a='rgba(255,255,255,1)rgba(1,10,100,0.1)rgba(1,10,100,10.123)rgba(1,10,100,-123.001)';
$a=preg_replace('/,[0-9.-]*)/',')',$a);
echo$a;
?>
執行結果:
rgba(255,255,255) rgba(1,10,100) rgba(1,10,100) rgba(1,10,100)