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程序设计有所帮助。

相关文章

php 面向对象的一个例子

复制代码 代码如下: <?php class person{ //下面是人的成员属性 var $name; //人的名字 var $sex; //人的性别 var $age; //...

PHP 程序授权验证开发思路

以下是我的一个想法,把服务器的php环境配置也应用在程序里面,生成一个许可字串,然后将字串写入到许可的文件代码中。就算是将程序原本不动地移到其它服务器上,程序都不能运行了。希望大家多多讨...

PHP实现的DES加密解密类定义与用法示例

本文实例讲述了PHP实现的DES加密解密类定义与用法。分享给大家供大家参考,具体如下: 今天写App接口的时候需要传递加密数据给APP端,于是就写了下面的DES加密类,亲测正确代码如下...

PHP连接SQLServer2005的方法

PHP连接SQLServer2005的方法

1.修改php.ini将extension=php_mssql.dll的注释删除保存。 修改php.in将mssql.secure_connection = Off改为mssql.sec...

linux下删除7天前日志的代码(php+shell)

PHP版本: 复制代码 代码如下: /** * 删除7天前的日志 * @param $logPath */ function del7daysAgoLog($logPath) { if(...