0

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 );
3
  • use the e modifier, or use preg_replace_callback. Commented Oct 20, 2012 at 14:14
  • @cbuckley - preg_replace_callback, yes. But the e modifier should be avoided. Commented Oct 20, 2012 at 14:16
  • @Spudley couldn't agree more; not sure why I even suggested it ;-) Commented Oct 20, 2012 at 14:19

1 Answer 1

2
$txt = preg_replace_callback('#<!--dle_video_begin:(.+?)-->(.+?)<!--dle_video_end-->#is', function($matches){
    return "[video=videoD({$matches[1]})]";
}, $txt);
Sign up to request clarification or add additional context in comments.

2 Comments

i'm getting the output of: [video=videoD(link)]
@Crazy_Bash I'm using the first capture group like in your examples. Use $matches[2] if you need the second one. Or var_dump($matches) in the callback to see how it looks and pick the one you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.