PHP - Youtube Bbcode Help
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', '/\[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 an 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 Similar TutorialsCode: [Select] $txt = preg_replace( "#\[yt\]http://www.youtube.com/watch?v=(.+?)\[/yt\]#is", '<embed src="http://www.youtube.com/v/\\1" type="application/x-shockwave-flash" wmode="transparent" width="512" height="313" allowfullscreen="true" />', $txt ); Okay this is my code just for inserting it into HTML, the problem is whenever I try to use: Code: [Select] [yt]http://www.youtube.com/watch?v=l1G7TJD6Xu0[/yt] On my form to enter it does not work? But if I use Code: [Select] $txt = preg_replace( "#\[yt\](.+?)\[/yt\]#is", '<embed src="http://www.youtube.com/v/\\1" type="application/x-shockwave-flash" wmode="transparent" width="512" height="313" allowfullscreen="true" />', $txt ); Code: [Select] [yt]l1G7TJD6Xu0[/yt] It works. But I want to use the full URL of the youtube, so I don't want my users to copy/paste just the "l1G7TJD6Xu0" Code , any help? Thank you Hi guys, In an application I'm working on, I'm looking to embed a youtube video with [YOUTUBE][/YOUTUBE]. Code: [Select] echo preg_replace('#(?:<\>]+href=\")?(?:http://)?((?:[a-zA-Z]{1,4}\.)?youtube.com/(?:watch)?\?v=(.{11}?))[^"]*(?:\"[^\<\>]*>)?([^\<\>]*)(?:)?#', '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/'.$matches[2].'"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'.$matches[2].'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>', $ENTIREPAGE?); The problem is that the video appears with a slider control at the bottom. How do I get rid of the Youtube slider control at the bottom? Thanks. How could I from the varying URLs parse only the YouTube video ID? http://www.youtube.com/watch?v=SwrawcORlp0&feature=player_embedded http://www.youtube.com/watch?v=SwrawcORlp0&feature=popular How can I from the URLs above only extract the id into a variable $url SwrawcORlp0 Thanks, df ok bare with me if this sounds stupid. How do i get it so that bbcode can be added within a textarea tag? im assuming it is a lot of str_replace. is there a tutorial on this somewhere? Hey, I need help with my BBCode function... im trying to allow it to embed you tube videos but im kinda confused as to how i can do it when i need the link to be in the bbcode html ouput twice with my current method. Here is my function: http://www.paste.to/MzE3Mg== I could not post the script as it was messing up with this site's BBcode. Any one can help me please ? Thankss I'm trying to work on BBCode for a forum. I have this: Code: [Select] <?php $bb_Code = array( '[ code]' => '<code>', '[ /code]' => '</code>' ); foreach ($bb_Code as $value => $replace) { $text = str_replace($value, $replace, $text); } ?> Question is.. how would I get it so when I insert information into the database it gets cleaned (strip_tags, etc.) but doesn't disturb what is in the [ code ] tags? So basically it makes the html, etc. in the [ code ] tags just plain text? Thanks in advanced. Hello guys, i need help with my BBcoding ... Its about browser game.. but i need someone who has some time to listen me about how things work and than help me.. every time i put : when sending message ingame i automaticly get smiley ... but please if anyone have time let me know Best Regards when posting a new message on my forum and it contains a url. How do i automatically add the bbcode url tags to a url in the message? This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=354638.0 Code: [Select] [b][i][u] test test test test test test test test test test test test test test test. [/b][/i]/[u] If I need to cut the first five words, the bbcode closing tags will be remove. hi, i have the following which parses the quote tag and replaces it with a span $bb[] = "#\[quote\](.*?)\[/quote\]#si"; $html[] = "<span class='quote'>\\1</div>"; what i would like however is for the bbcode to be Quote from: xxxx where xxxx is the name of the person you are quoting. so how would i parse this? I also need the same for font color but if someone can provide a solution to this one then i think i could work it out. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=348145.0 i am wanting to add a code tag to my bbcode list. Anything within this tag will be printed as is(like the html code). I have tried using htmlspecialchars() but it isnt printing the code. Here is the parser section for the tag: $patern = "#\[code = ([^\]]*)\]([^\[]*)\[/code\]#i"; $replace = "<table class=\"code\"> <tr> <th>\\1</th> </tr> <tr> <td>".htmlspecialchars('\\2')."</td> </tr> </table>"; $str=preg_replace($patern, $replace, $str); Any ideas? Hi there, This isn't really a bbcode parser problem, but it kind of is. And I am awful at explaining things, as you have noticed. The problem is that I'd like to allow input for the main page of a site. But the part has this structu Code: [Select] <div class='mainheader'>TITLE</div> <div class='content'> The content of the webpage blabla</div> I'd like this whole page to be changeable, so also the title and the content. But how can I ensure that people use the content div after the mainheader div? I would like it if it were possible that they only needed to 'select' the header, how can I do this? Thanks in advance! Right now i used the following code to convert bbcode to html/php. i also need to incorporate QUOTE=name and URLS as well..how do i do that? Code: [Select] function bbcode_format ($str) { $str = htmlentities($str); $start = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[a\=(.*?)\](.*?)\[\/a\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[header\](.*?)\[\/header\]/is' ); $finish = array( '<strong>$1</strong>', '<em>$1</em>', '<u>$1</u>', '<a href="$1">$2</a>', '<span style="color: $1">$2</span>', '<img src="$1" />', '<span class="h3">$1</span>' ); $str = preg_replace ($start, $finish, $str); return $str; } This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=317329.0 I'm trying to work on BBCode for a forum. Code: [Select] <?php $bb_Code = array( '[ code]' => '<code>', '[ /code]' => '</code>' ); foreach ($bb_Code as $value => $replace) { $text = str_replace($value, $replace, $text); } ?> Question is.. how would I get it so when I insert information into the database it gets cleaned (strip_tags, etc.) but doesn't disturb what is in the [ code ] tags? So basically it makes the html, etc. in the [ code ] tags just plain text? Thanks in advanced. I was wonder how I could make some BBcode for my messaging system I made for a website. I made some simple ones like just by replace [ red ] with font color etc. I want to know how to do something like this: [ url = http://google . ca] Google [ / url ] without the spaces. ~AJ Everything works fine, unless I add this stupid thing to get rid of people using HTML Code: [Select] $text = pun_htmlspecialchars($text); Once I add that to my function, no bbcodes work at all? But I cant use html.. (which is good) but I need to beable to use BBCODE, and parse hackers from using html also, any help? MY CODE absolutely destroyed the forum page here it is: http://pastebin.com/jv7m47kn Ok, so i'm working on my forum software in PHP to both get some knowledge out of this and accomplish something in the run. While adding a BBCode parser, I ran into some trouble. This is what happened: http://ebulletin.ballindesign.com/message.php?id=1 As you can see, a <br /> tag shows up after EVERY line... Here is my BBCode parser: <?php function is_odd($intNumber) { if ($intNumber % 2 == 0 ) return true; else return false; } function badlink($link, $prefix) { if ($prefix == "mailto:") { if (strpos($link, "@") === FALSE || strpos($link, ".", (strpos($link, "@")+2)) === FALSE || substr_count($link, "@") > 1 || strpos($link, "@") == 0) { return 1; } } if (strpos($link, ".") == 0 || strpos($link, ".") == strlen($link) || (strpos($link, "/") < strpos($link, ".") && strpos($link, "/") !== FALSE)) { return 1; } }; function setlinks($r, $prefix) { if (substr($r, 0, strlen($prefix)) == $prefix) { $r = "\n".$r; } $r = str_replace("<br>".$prefix, "<br>\n".$prefix, $r); $r = str_replace(" ".$prefix, " \n".$prefix, $r); while (strpos($r, "\n".$prefix) !== FALSE) { list($r1, $r2) = explode("\n".$prefix, $r, 2); if (strpos($r2, " ") === FALSE && strpos($r2, "<br>") === FALSE) { if ($prefix != "mailto:") { $target = ' target="_blank"'; } else { $target = ""; } if (strpos($r2, ".") > 1 && strpos($r2, ".") < strlen($r2) && badlink($r2, $prefix) != 1) { $r = $r1.'<a href="'.$prefix.$r2.'"'.$target.'><font size="2" color="blue">'.$prefix.$r2.'</font></a>'; } else { $r = $r1.$prefix.$r2; } } else { if (strpos($r2, " ") === FALSE || ( strpos($r2, " ") > strpos($r2, "<br>") && strpos($r2, "<br>") !== FALSE)) { list($r2, $r3) = explode("<br>", $r2, 2); if (badlink($r2, $prefix) != 1) { $r = $r1.'<a href="'.$prefix.$r2.'"'.$target.'><font size="3" color="blue">'.$prefix.$r2.'</font></a><br>'.$r3; } else { $r = $r1.$prefix.$r2.'<br>'.$r3; } } else { list($r2, $r3) = explode(" ", $r2, 2); if (strpos($r2, ".") > 1 && strpos($r2, ".") < strlen($r2) && badlink($r2, $prefix) != 1) { $r = $r1.'<a href="'.$prefix.$r2.'"'.$target.'><font size="3" color="blue">'.$prefix.$r2.'</font></a> '.$r3; } else { $r = $r1.$prefix.$r2.' '.$r3; } } } } return $r; }; function BBCode($r) { $r = trim($r); $r = htmlentities($r); $r = str_replace("\r\n","<br>",$r); $r = str_replace("\r\n","</br>",$r); $r = str_replace("[b]","<b>",$r); $r = str_replace("[/b]","</b>",$r); $r = str_replace("[img]http://","<img src='",$r); $r = str_replace("[/img]","'>",$r); $r = str_replace("[IMG]http://","<img src='",$r); $r = str_replace("[/img]","'>",$r); $r = str_replace("[s]","<s>",$r); $r = str_replace("[/s]","</s>",$r); $r = str_replace("[ul]","<ul>",$r); $r = str_replace("[/ul]","</ul>",$r); $r = str_replace("[list][li]","<li>",$r); $r = str_replace("[/li][/list]","</li>",$r); $r = str_replace("[ol]","<ol>",$r); $r = str_replace("[/ol]","</ol>",$r); $r = str_replace("[quote]","<br /><table width='80%' bgcolor='#ffff66' align='center'><tr><td style='border: 1px dotted black'><font color=black><b>Quote:<br></b>",$r); $r = str_replace("[/quote]","</font></td></tr></table>",$r); $r = str_replace("[i]","<i>",$r); $r = str_replace("[/i]","</i>",$r); $r = str_replace("[u]","<u>",$r); $r = str_replace("[/u]","</u>",$r); $r = str_replace("[spoiler]",'[spoiler]<font bgcolor ="#000000" color="#DDDDDD">',$r); $r = str_replace("[/spoiler]","</font>[/spoiler]",$r); //set [link]s while (strpos($r, "[link=") !== FALSE) { list ($r1, $r2) = explode("[link=", $r, 2); if (strpos($r2, "]") !== FALSE) { list ($r2, $r3) = explode("]", $r2, 2); if (strpos($r3, "[/link]") !== FALSE) { list($r3, $r4) = explode("[/link]", $r3, 2); $target = ' target="_blank"'; if (substr($r2, 0, 7) == "mailto:") { $target = ""; } $r = $r1.'<a href="'.$r2.'"'.$target.'><font size="3" color="blue">'.$r3.'</font></a>'.$r4; } else { $r = $r1."[link\n=".$r2."]".$r3; } } else { $r = $r1."[link\n=".$r2; } } $r = str_replace("[link\n=","[link=",$r); ////[link] ///default url link setting $r = setlinks($r, "http://"); $r = setlinks($r, "https://"); $r = setlinks($r, "ftp://"); $r = setlinks($r, "mailto:"); ////links ///emoticons $r = str_replace(":)",'<img src="images/smilie.gif">',$r); $r = str_replace(":(",'<img src="images/sad.gif">',$r); $r = str_replace(":angry:",'<img src="images/angry.gif">',$r); $r = str_replace(":D",'<img src="images/biggrin.gif">',$r); $r = str_replace(":blink:",'<img src="images/blink.gif">',$r); $r = str_replace(":blush:",'<img src="images/blush.gif">',$r); $r = str_replace("B)",'<img src="images/cool.gif">',$r); $r = str_replace("<_<",'<img src="images/dry.gif">',$r); $r = str_replace("^_^",'<img src="images/happy.gif">',$r); $r = str_replace(":huh:",'<img src="images/confused.gif">',$r); $r = str_replace(":lol:",'<img src="images/laugh.gif">',$r); $r = str_replace(":o",'<img src="images/ohmy.gif">',$r); $r = str_replace(":fear:",'<img src="images/fear.gif">',$r); $r = str_replace(":rolleyes:",'<img src="images/rolleyes.gif">',$r); $r = str_replace(":sleep:",'<img src="images/sleep.gif">',$r); $r = str_replace(":p",'<img src="images/tongue.gif">',$r); $r = str_replace(":P",'<img src="images/tongue.gif">',$r); $r = str_replace(":unsu ",'<img src="images/unsure.gif">',$r); $r = str_replace(":wacko:",'<img src="images/wacko.gif">',$r); $r = str_replace(":wink:",'<img src="images/wink.gif">',$r); $r = str_replace(":wub:",'<img src="images/wub.gif">',$r); $r = trim($r); return $r; } ?> |