May 3, 201016 yr Hey sorry that i keep posting so many questions but i just have one more how would you create a BB code to like show a youtube video like this [video]You tube video link[/video] any help would be appriciated thanks in advance
May 5, 201016 yr Pretty simple function as long as you match the $find indices with the $replace it should work a treat. I'll look implementing a caching feature in the future. http://www.kieranallen.com/2010/05/simple-bbcode/ <?php function textToBB($string) { // Warning: YOU MUST htmlspecialchar this raw user input. $string = htmlspecialchars($string,ENT_QUOTES,'utf-8'); // Format nicely $string = nl2br($string); // Patterns $find = array( '/\[video\](.*?)\[\/video\]/is', '/:\)/' ); // Replace with $replace = array( '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/$1&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$1&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>', '<img src="images/happy.gif" alt="happy" />' ); // Join them up $string = preg_replace($find, $replace, $string); // return parsed code return $string; } $string = 'lots of text, etc etc look at my Youtube video: [video]BIduOvEoVeQ[/video]'; echo textToBB($string);
Create an account or sign in to comment