lifetalk Posted November 15, 2008 Share Posted November 15, 2008 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 More sharing options...
thebadbad Posted November 15, 2008 Share Posted November 15, 2008 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. Link to comment https://forums.phpfreaks.com/topic/132846-preg_replace_callback-error-please-help/#findComment-690921 Share on other sites More sharing options...
lifetalk Posted November 16, 2008 Author Share Posted November 16, 2008 Strange.. if I add pattern delimiters and escape the rest of the stuff, the script does not function. Preg_replace does not work then Link to comment https://forums.phpfreaks.com/topic/132846-preg_replace_callback-error-please-help/#findComment-691147 Share on other sites More sharing options...
thebadbad Posted November 16, 2008 Share Posted November 16, 2008 If you're trying to grab the video ID in a megavideo.com URL, try this pattern instead: define("MVEM_REGEXP", "~http://www\.megavideo\.com/\?v=([0-9a-z]+)~i"); Link to comment https://forums.phpfreaks.com/topic/132846-preg_replace_callback-error-please-help/#findComment-691191 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.