Replace any consecutive character in the string with a corresponding character .? Php1, replace any space in the string with a $ str1ABC; echoxmp; echo1:; echopreg_replace (s +, $ str1); echoxmp; 2, replace any consecutive character M in the string // 1. replace any space in the string with one
$ Str1 = a B C;
Echo ; <BR> echo 1:; <BR> echo preg_replace ("/s +/", $ str1); <BR> echo ;
// 2. replace any consecutive character M in the string with one M
Echo 2 :;
$ Str1 = AMMMBMMMMCMM;
Echo preg_replace ("/M +/", M, $ str1 ).
;
// 3. replace any consecutive character in the string with a corresponding character
Echo 3:
;
$ Str1 = acccb cccccggg ooo yyyfffxxxzzzzz;
Echo $ str1.
;
$ Str2 =;
$ I = 0;
For ($ I = 0; $ I {
$ Str2 = $ str2. $ str1 {$ I };
$ J = 1;
While ($ str1 {$ I }=$ str1 {$ I + $ j })
$ J ++;
$ I = $ I + $ j-1;
}
Echo $ str2.
;
// 4. replace any consecutive character in the string with a corresponding character
Echo 4:
;
$ Str1 = acccb cccccggg ooo yyyfffxxxzzzzz;
Echo $ str1.
;
$ Len = strlen ($ str1 );
$ Str2 = $ str1 [0];
$ Ch = $ str2;
For ($ I = 1; $ I <$ len; $ I ++ ){
$ Ch2 = $ str1 [$ I];
If ($ ch! = $ Ch2 ){
$ Str2. = $ ch2;
$ Ch = $ ch2;
}
}
Echo $ str2 ."
";
// 5. replace any consecutive character in the string with a corresponding character
Echo 5:
;
$ Str1 = acccb cccccggg ooo yyyfffxxxzzzzz;
Echo preg_replace ("/(.) \ 1 +/", "[url = file: // \ 1] \ 1 [/url]", $ str1 ).
;
?>
Http://www.bkjia.com/PHPjc/508229.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/508229.htmlTechArticle? Php // 1, replace any space in the string with A $ str1 = a B C; echo xmp; echo 1:; echo preg_replace ("/s + /",, $ str1); echo/xmp; // 2, replace any consecutive character M in the string...