㈠ php 字元串替換
<?php$stirng ="aaaaa aaaaa aaaaaa";$string = str_replace("", "<a href= http://www..com></a>", $string);echo $string;?>
㈡ php怎麼替換掉一段字元串 .
思路: 獲取img src的開始位置與結束位置, 然後字元串函數截取字元串出來,然後字元串函數替換
或者可以用『 「 』講字元串轉化為數組 替換src的value 在從數組轉化為字元串。
關鍵在於找到要替換的對象
㈢ php字元串對應替換(把一些拼音換成對應的漢字)
PHP str_ireplace() 函數使用一個字元串替換字元串中的另一些字元。
<?php
$find = "anyang";
$replace = "安陽";
$arr = "anyang測試anyang";
$newstr = str_ireplace($find,$replace,$arr);
echo $newstr;
?>
使用這個str_ireplace()就能替換了,而且還不用擔心大小寫問題,如果不用考慮大小寫那就使用str_replace()即可!
參數如下:
str_ireplace(find,replace,string,count)
參數 描述
find 必需。規定要查找的值。
replace 必需。規定替換 find 中的值的值。
string 必需。規定被搜索的字元串。
count 可選。一個變數,對替換數進行計數。
歡迎採納!
㈣ php 將字元串中 中文替換
<?php
$test = "我是chinese,sdgwping";
$len = strlen($test);
$str = '';
$en = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
for($i=0;$i<$len;$i++){
if(in_array($test[$i],$en)){
$str .= $test[$i];
}
}
echo $str;
?>
這段代碼可以把英文字元提取出來,如果你需要提取其他的字元,可以添加到那個en數組里
㈤ php如何替換中文字元串最後一個字,我要把句子中的 "啊、呀、哈"這些沒用的詞都換成"啊" ,怎麼實現最快
preg_replace('/啊|呀|哈$/'), '啊', $string)
㈥ php 字元串查找和替換
使用PHP的正則表達式替換函數,用表達式/(\?|&)ddd=.*?(&|$)/進行替換就可以了。
<?php
$str = 'afda?abc=12&ddd=33&jjj=xx';
$str = preg_replace('/(\?|&)ddd=.*?(&|$)/', '\\1ddd=50\\2', $str);
echo $str;
?>
㈦ php字元串替換,每次替換一個如何實現
mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1[, int &$count ]] )
$limit參數指定替換次數
http://www.php.net/manual/zh/function.preg-replace.php
㈧ PHP或者Mysql怎麼把中文字元串的第一個字元替換成對應的英文大寫字母
function getFirstCharter($str){
if(empty($str)){return '';}
$fchar=ord($str{0});
if($fchar>=ord('A')&&$fchar<=ord('z')) return strtoupper($str{0});
$s1=iconv('UTF-8','gb2312',$str);
$s2=iconv('gb2312','UTF-8',$s1);
$s=$s2==$str?$s1:$str;
$asc=ord($s{0})*256+ord($s{1})-65536;
echo $asc;
if($asc>=-20319&&$asc<=-20284) return 'A';
if($asc>=-20283&&$asc<=-19776) return 'B';
if($asc>=-19775&&$asc<=-19219) return 'C';
if($asc>=-19218&&$asc<=-18711) return 'D';
if($asc>=-18710&&$asc<=-18527) return 'E';
if($asc>=-18526&&$asc<=-18240) return 'F';
if($asc>=-18239&&$asc<=-17923) return 'G';
if($asc>=-17922&&$asc<=-17418) return 'H';
if($asc>=-17417&&$asc<=-16475) return 'J';
if($asc>=-16474&&$asc<=-16213) return 'K';
if($asc>=-16212&&$asc<=-15641) return 'L';
if($asc>=-15640&&$asc<=-15166) return 'M';
if($asc>=-15165&&$asc<=-14923) return 'N';
if($asc>=-14922&&$asc<=-14915) return 'O';
if($asc>=-14914&&$asc<=-14631) return 'P';
if($asc>=-14630&&$asc<=-14150) return 'Q';
if($asc>=-14149&&$asc<=-14091) return 'R';
if($asc>=-14090&&$asc<=-13319) return 'S';
if($asc>=-13318&&$asc<=-12839) return 'T';
if($asc>=-12838&&$asc<=-12557) return 'W';
if($asc>=-12556&&$asc<=-11848) return 'X';
if($asc>=-11847&&$asc<=-11056) return 'Y';
if($asc>=-11055&&$asc<=-10247) return 'Z';
return null;
}
echo getFirstCharter('李');
㈨ php 如何將字元串中的"\"替換為"/"
str_replace('\\','/',"E:\phpsite\zhengtu\flv");
與平台相關的東西:比如目錄分割符號。請用php內置常量:DIRECTORY_SEPARATOR