UnknownPlayer Posted September 26, 2010 Share Posted September 26, 2010 I have this function: function bbcode($input){ $input = strip_tags($input); $input = htmlentities($input); $search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[url=http://(.*?)\](.*?)\[\/url\]/is', '/\[font color=(.*?) size=(.*?) face=(.*?)\](.*?)\[\/font\]/is', ); $replace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<img src="$1">', '<a href="$1">$2</a>', '<font style="color:$1;font-size:$2;font-face:$3">$4</font>', ); return preg_replace($search,$replace,$input); } Now when i use this command($komentar is variable which is loaded from mysql): echo bbcode($komentar); it shows me this error: Warning: preg_replace() [function.preg-replace]: Unknown modifier '/' in /home/dotars/public_html/includes/functions.php on line 212 What is wrong here ? :S Link to comment https://forums.phpfreaks.com/topic/214439-bbcode-preg_replace-error/ Share on other sites More sharing options...
Pikachu2000 Posted September 26, 2010 Share Posted September 26, 2010 You've used your delimiter without escaping it. '/\(.*?)\[\/url\]/is', should be '/\(.*?)\[\/url\]/is', Link to comment https://forums.phpfreaks.com/topic/214439-bbcode-preg_replace-error/#findComment-1115884 Share on other sites More sharing options...
UnknownPlayer Posted September 26, 2010 Author Share Posted September 26, 2010 Thanks.. Link to comment https://forums.phpfreaks.com/topic/214439-bbcode-preg_replace-error/#findComment-1115899 Share on other sites More sharing options...
UnknownPlayer Posted September 26, 2010 Author Share Posted September 26, 2010 How can i put youtube embeding code in bbcode. I mean this code: <object width="660" height="405"> <param name="movie" value="(.*?)\" /> <param name="allowFullScreen" value="true" /> <param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="660" height="405" src="(.*?)\" allowscriptaccess="always" allowfullscreen="true"></embed> </object> To put in bbcode to bi like this: [yt]link[/yt] I dont know how to du that becouse i have these /\/\/\/ :S Link to comment https://forums.phpfreaks.com/topic/214439-bbcode-preg_replace-error/#findComment-1115903 Share on other sites More sharing options...
Pikachu2000 Posted September 26, 2010 Share Posted September 26, 2010 You've used your delimiter without escaping it. '/\(.*?)\[\/url\]/is', should be '/\(.*?)\[\/url\]/is', I guess I should have looked at that post after submitting it. The BBCode parser had some unintended "effects" on it. Should have read: '/\(.*?)\[\/url\]/is', should be '/\(.*?)\[\/url\]/is', Link to comment https://forums.phpfreaks.com/topic/214439-bbcode-preg_replace-error/#findComment-1115909 Share on other sites More sharing options...
UnknownPlayer Posted September 26, 2010 Author Share Posted September 26, 2010 I've done that, but can you or someone help me with [yt] tag? This tag work like this, but address of youtube address is http://www.youtube.com/watch?v=A6ZLlk, but on embed link link is http://youtube.com/watch?v=A6ZLlk can someone help me to transfer http://www.youtube.com/watch?v=A6ZLlk to http://youtube.com/watch?v=A6ZLlk ? Link to comment https://forums.phpfreaks.com/topic/214439-bbcode-preg_replace-error/#findComment-1115918 Share on other sites More sharing options...
Pikachu2000 Posted September 26, 2010 Share Posted September 26, 2010 For that, str_replace() should be sufficient. <?php $find = array('www.', 'watch?v='); $repl = array('', 'v/'); $yt = 'http://www.youtube.com/watch?v=A6ZLlk'; echo str_replace($find, $repl, $yt); // Echos 'http://youtube.com/v/A6ZLlk' ?> Link to comment https://forums.phpfreaks.com/topic/214439-bbcode-preg_replace-error/#findComment-1115937 Share on other sites More sharing options...
UnknownPlayer Posted September 26, 2010 Author Share Posted September 26, 2010 Another problem about this :S please help function bbcode($input){ $input = strip_tags($input); $input = htmlentities($input); $search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[url=http://(.*?)\](.*?)\[\/url\]/is', '/\[color=(.*?)\](.*?)\[\/color\]/is', '/\[yt\](.*?)\[\/yt\]/is', ); $replace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<img src="$1" style="border:0">', '<a href="$1">$2</a>', '<font style="color:$1">$2</font>', '<object width="660" height="405"> <param name="movie" value="'.str_replace("watch?v=", "v/", $1).'" /> <param name="allowFullScreen" value="true" /> <param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="660" height="405" src="'.str_replace("watch?v=", "v/", $1).'" allowscriptaccess="always" allowfullscreen="true"></embed> </object>', ); return nl2br(preg_replace($search,$replace,$input)); } There is error on code: <param name="movie" value="'.str_replace("watch?v=", "v/", $1).'" /> and on: <param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="660" height="405" src="'.str_replace("watch?v=", "v/", $1).'" allowscriptaccess="always" allowfullscreen="true"> How can i use str_replace in this situation ? :S Link to comment https://forums.phpfreaks.com/topic/214439-bbcode-preg_replace-error/#findComment-1116055 Share on other sites More sharing options...
UnknownPlayer Posted September 27, 2010 Author Share Posted September 27, 2010 Can someone please help ? Link to comment https://forums.phpfreaks.com/topic/214439-bbcode-preg_replace-error/#findComment-1116503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.