doujuanqi2909 2012-10-20 14:12
浏览 53
已采纳

PHP:在preg_replace中调用函数

The below code responsible for bbcode tags in dle script. "\1" is the link which i would like to call with function, but instead I'm getting plain text

        $txt = preg_replace( "#<!--dle_video_begin:(.+?)-->(.+?)<!--dle_video_end-->#is", '[video=\\1]', $txt );

my function

function videoD ($str) {
        if (strpos($str,'http://') !== false) {
                $vid = uppod_encode($str);
                echo (uppod_encode($str));

        } else {
                $vid = uppod_decode($str);
                echo (uppod_encode($vid));
        }
}

what i've tried:

$txt = preg_replace( "#<!--dle_video_begin:(.+?)-->(.+?)<!--dle_video_end-->#is", '[video=videoD(\\1)]', $txt );


$txt = preg_replace( "#<!--dle_video_begin:(.+?)-->(.+?)<!--dle_video_end-->#is", '[video=videoD(1)]', $txt );

$txt = preg_replace( "#<!--dle_video_begin:(.+?)-->(.+?)<!--dle_video_end-->#is", '[video=\\videoD(1)]', $txt );
  • 写回答

1条回答 默认 最新

  • duanpa1898 2012-10-20 14:18
    关注
    $txt = preg_replace_callback('#<!--dle_video_begin:(.+?)-->(.+?)<!--dle_video_end-->#is', function($matches){
        return "[video=videoD({$matches[1]})]";
    }, $txt);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验