php正则preg_replace_callback函数用法实例,pregreplace正则_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php正则preg_replace_callback函数用法实例,pregreplace正则_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1410字,纯文字阅读大概需要3分钟。
内容图文
![php正则preg_replace_callback函数用法实例,pregreplace正则_PHP教程](/upload/InfoBanner/zyjiaocheng/188/f288b35fe9254f209e467f9d1134d816.jpg)
php正则preg_replace_callback函数用法实例,pregreplace正则
本文实例讲述了php正则preg_replace_callback函数的用法。分享给大家供大家参考。具体实现方法如下:
php正则表达式功能强大,本范例演示了preg_replace_callback函数的用法
// Define a dummy text, for testing... $Text = "Title: Hello world!\n"; $Text .= "Author: Jonas\n"; $Text .= "This is a example message!\n\n"; $Text .= "Title: Entry 2\n"; $Text .= "Author: Sonja\n"; $Text .= "Hello world, what's up!\n"; // This function will replace specific matches // into a new form function RewriteText($Match){ // Entire matched section: // --> /.../ $EntireSection = $Match[0]; // --> "\nTitle: Hello world!" // Key // --> ([a-z0-9]+) $Key = $Match[1]; // --> "Title" // Value // --> ([^\n\r]+) $Value = $Match[2]; // --> "Hello world!" // Add some bold () tags to around the key to return '' . $Key . ': ' . $Value; } // The regular expression will extract and pass all "key: value" pairs to // the "RewriteText" function that is definied above $NewText = preg_replace_callback('/[\r\n]([a-z0-9]+): ([^\n\r]+)/i', "RewriteText", $Text); // Print the new modified text print $NewText;
希望本文所述对大家的php程序设计有所帮助。
http://www.bkjia.com/PHPjc/1011257.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1011257.htmlTechArticlephp正则preg_replace_callback函数用法实例,pregreplace正则 本文实例讲述了php正则preg_replace_callback函数的用法。分享给大家供大家参考。具体实现...
内容总结
以上是互联网集市为您收集整理的php正则preg_replace_callback函数用法实例,pregreplace正则_PHP教程全部内容,希望文章能够帮你解决php正则preg_replace_callback函数用法实例,pregreplace正则_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。