位置: 编程技术 - 正文
推荐整理分享PHP:mb_ereg_replace_callback()的用法_mbstring函数,希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!
(PHP 5 >= 5.4.1)
mb_ereg_replace_callback — Perform a regular expresssion seach and replace with multibyte support using a callback
说明 string mb_ereg_replace_callback ( string $pattern , callable $callback , string $string [, string $option = "msr" ] )Scans string for matches to pattern, then replaces the matched text with the output of callback function.
The behavior of this function is almost identical to mb_ereg_replace(), except for the fact that instead of replacement parameter, one should specify a callback.
参数pattern
The regular expression pattern.
Multibyte characters may be used in pattern.
callbackA callback that will be called and passed an array of matched elements in the subject string. The callback should return the replacement string.
Youll often need the callback function for a mb_ereg_replace_callback() in just one place. In this case you can use an anonymous function to declare the callback within the call to mb_ereg_replace_callback(). By doing it this way you have all information for the call in one place and do not clutter the function namespace with a callback functions name not used anywhere else.
stringThe string being checked.
optionMatching condition can be set by option parameter. If i is specified for this parameter, the case will be ignored. If x is specified, white space will be ignored. If m is specified, match will be executed in multiline mode and line break will be included in .. If p is specified, match will be executed in POSIX mode, line break will be considered as normal character. Note that e cannot be used for mb_ereg_replace_callback().
返回值The resultant string on success, or FALSE on error.
注释Note:
mb_regex_encoding()指定的内部编码或字符编码将会当作此函数用的字符编码。
范例
Example #1 mb_ereg_replace_callback() example
<?php//thistextwasusedin//wewanttogetthisuptodatefor$text="Aprilfoolsdayis//n";$text.="Lastchristmaswas//n";//thecallbackfunctionfunctionnext_year($matches){//asusual:$matches[0]isthecompletematch//$matches[1]thematchforthefirstsubpattern//enclosedin'(...)'andsoonreturn$matches[1].($matches[2]+1);}echomb_ereg_replace_callback("(d{2}/d{2}/)(d{4})","next_year",$text);?>以上例程会输出:
Example #2 mb_ereg_replace_callback() using anonymous function supported in PHP 5.3.0 or later
<?php//thistextwasusedin//wewanttogetthisuptodatefor$text="Aprilfoolsdayis//n";$text.="Lastchristmaswas//n";echomb_ereg_replace_callback("(d{2}/d{2}/)(d{4})",function($matches){return$matches[1].($matches[2]+1);},$text);?> 参见mb_regex_encoding() - Set/Get character encoding for multibyte regex mb_ereg_replace() - Replace regular expression with multibyte support Anonymous functions callback 类型的信息
PHP:mb_ereg_search_getregs()的用法_mbstring函数 mb_ereg_search_getregs(PHP4=4.2.0,PHP5)mb_ereg_search_getregsRetrievetheresultfromthelastmultibyteregularexpressionmatch说明arraymb_ereg_search_getregs(void)Retrievetheresultfromthelastmultibyteregu
PHP:mb_ereg_search_getpos()的用法_mbstring函数 mb_ereg_search_getpos(PHP4=4.2.0,PHP5)mb_ereg_search_getposReturnsstartpointfornextregularexpressionmatch说明intmb_ereg_search_getpos(void)Returnsthestartpointforthenextregularexpressionmatch.参数
PHP:mb_encode_numericentity()的用法_mbstring函数 mb_encode_numericentity(PHP4=4.0.6,PHP5)mb_encode_numericentityEncodecharactertoHTMLnumericstringreference说明stringmb_encode_numericentity(string$str,array$convmap[,string$encoding=mb_internal_enco
标签: PHP:mb_ereg_replace_callback()的用法_mbstring函数
本文链接地址:https://www.jiuchutong.com/biancheng/275028.html 转载请保留说明!友情链接: 武汉网站建设