PHP实现通过正则表达式替换回调的内容标签

yipeiwu_com6年前PHP代码库

本文实例讲述了PHP实现通过正则表达式替换回调的内容标签。分享给大家供大家参考。具体实现方法如下:

function my_wp_plugin_tag_action($content,$tag,$function,$args = FALSE) {
 // match all regular expressions
 preg_match_all($tag,$content,$matches);
 if (count($matches)>0) {
  // filter duplicates
  $matches = array_unique($matches);
  // loop through
  $tag_results = array();
  $found_tags = array();
  foreach ($matches as $idx => $match) {
   //build arg array
   $full_tag = array_shift($match);
   //call function, adding function output and full tag text to replacement array
   $tag_results[] = my_wp_plugin_buffer_func($function,$match);
   $found_tags[] = $full_tag;
  }
  // replace all tags with corresponding text
  $content = str_replace($found_tags,$tag_results,$content);
 }
 return $content;
}

希望本文所述对大家的php程序设计有所帮助。

相关文章

thinkphp如何获取客户端IP

thinkphp框架中系统内置了get_client_ip方法用于获取客户端的IP地址,使用示例: $ip = get_client_ip(); 除了thinkphp内置get_cl...

PHP设计模式之建造者模式定义与用法简单示例

本文实例讲述了PHP设计模式之建造者模式。分享给大家供大家参考,具体如下: 建造者模式: 将复杂对象的创建过程和表示进行分离(好吧,我也看不懂什么意思1)。 来点我人类能听懂的话:...

php加速器eAccelerator的配置参数、API详解

它还能够对脚本进行优化以便加速它们的执行速度。利用eAccelerator可以减少服务器的负载并提高PHP代码的执行时间。 eAccelerator配置选项:复制代码 代码如下:zend...

php.ini修改php上传文件大小限制的方法详解

打开php.ini,首先找到file_uploads = on ;是否允许通过HTTP上传文件的开关。默认为ON即是开upload_tmp_dir ;文件上传至服务器上存储临时文件的地方...

PHP正则删除html代码中a标签并保留标签内容的方法 原创

本文实例讲述了PHP正则删除html代码中a标签并保留标签内容的方法。分享给大家供大家参考,具体如下: 一、问题: 有HTML代码如: <div>欢迎访问【宜配屋www....