脚本宝典收集整理的这篇文章主要介绍了php – 如何使用preg_replace获取替换的文本?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$comment = preg_replace( '/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i','',$strText );
来自PHP.net的示例:
<?PHP // this text was used in 2002 // we want to get this up to date for 2003 $text = "April fools day is 04/01/2002\n"; $text.= "Last christmas was 12/24/2001\n"; // the callback function function next_year($matches) { // as usual: $matches[0] is the complete match // $matches[1] the match for the First subpattern // enclosed in '(...)' and so on return $matches[1].($matches[2]+1); } echo preg_replace_callback( "|(\d{2}/\d{2}/)(\d{4})|","next_year",$text); ?>
以上是脚本宝典为你收集整理的php – 如何使用preg_replace获取替换的文本?全部内容,希望文章能够帮你解决php – 如何使用preg_replace获取替换的文本?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。