Jump to content

preg_replace_callback error. Please help


lifetalk

Recommended Posts

Hi there,

 

I was trying to create a wordpress plugin to search for a specific string in a post, and replace it with another (substituting part of the original string in the one being replaced).

 

Here's what my code looks like:

 

<?php
/*
Plugin Name: Megavideo iFrame Embed Plugin
Plugin URI: http://www.rapidpremium.net
Plugin Description: Allows you to insert the iframe based megavideo embed player.
Version: 1.0
Author: Hamza Yousuf
Author URI: http://www.rapidpremium.net

*/

//Let's start

define("MVEM_REGEXP", "http://www.megavideo.com/?v=([[:print:\]]+)");
define("MVEM_TARGET", "<iframe width=\"476\" scrolling=\"no\" height=\"523\" frameborder=\"0\" src=\"http://www.megavideo.com/?v=###URL###\" border=\"0\" style=\"float: left; margin-left: -26px; margin-top: -148px; Margin-Bottom: -148px;\">");

//Let's try a function now

function mvem_plugin_callback($match)
{
$single_tag = explode("=", rtrim($match[0]));
$output = MVEM_TARGET;
$output = str_replace("###URL###", $single_tag[1], $output);
return ($output);
}

//Another function

function mvem_plugin($content)
{
return (preg_replace_callback(MVEM_REGEXP, 'mvem_plugin_callback', $content));
}

//Adding filters

add_filter('the_content', 'mvem_plugin');
add_filter('the_content_rss', 'mvem_plugin');

//Wrapping Up

?>

 

I know this code is not entirely correct. This is my first time ever writing PHP code (and I am barely an amateur).

 

The error I get..

(the plugin activates alright.. so there ain't any syntax error I suppose).. the error I get when the actual replacing of the string appears in the post.. is

 

Warning: preg_replace_callback() [function.preg-replace-callback]: Delimiter must not be alphanumeric or backslash in C:\Program Files\VertrigoServ\www\wordpress\wp-content\plugins\mvem.php on line 31

 

Any and all help is highly appreciated :)

Link to comment
https://forums.phpfreaks.com/topic/132846-preg_replace_callback-error-please-help/
Share on other sites

You're missing pattern delimiters (added tildes). And you should also escape literal dots - dunno if the rest of the pattern is alright:

 

define("MVEM_REGEXP", "~http://www\.megavideo\.com/\?v=([[:print:\]]+)~");

 

Edit: Also escaped the question mark.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.