PHP - Regex Synthax In Prism Synthax Highlighter Bbcode Application
I am building a bbcode system to integrate the prism synthax highlighter into my custom php bulletin board; there are some issues with my regex synthax. This is what i need to achieve:
Allow users to post
text alone,
or code and text but never code alone.
Code may be preceded by text or text may be included after the code.
bbcode
// Function to convert BBcode in HTML tags function formatBBcode($str) { $str = preg_replace('/\[code](.+?)\[\/code]/si', '<section class="language-php"><pre><code>$1</code></pre></section>', $str); return $str; }validation code: $var = '[code]<!DOCTYPE html>[/code] Some text'; // post text alone or nothing at all if(!preg_match('~[[:alnum:]]~', trim(preg_replace('~\[code\].*?\[/code\]~', "", $var)))) { echo 'Please add some text...'; } else { // empty code tags if(preg_match('~\[code\]\s*\[/code\]~', $var)) { echo 'The code tags can not be empty!'; // If there are no issues } else { echo "Everything is ok!"; } }With the present code, this is my observation when code alone is posted: If the code is on a single line the 'Please add some text' warning is thrown up. e.g //This throws up warning 'please add some text' [code]some code[/code]However if the code is on multiple lines, then it gets posted without any warning. e.g //This does not throw up any warning but gets posted [code]some code [/code]I need help in resolving this. Thanks. Edited by terungwa, 23 May 2014 - 10:59 AM. Similar TutorialsI was able to install CKEditor and the plugin "Syntax Highlighter".
Yet the plugin does not work. This is how the code comes out:
<div> <H1>You are Writing this Post</H1> <form action="insert.php" method="POST"> <input type="text" name="title" /> <br /> <textarea type="text" name="post"></textarea> <br /> <input type="submit&qAny suggestions? Edited by glassfish, 03 October 2014 - 06:16 AM. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=333143.0 Hi, I need a small help. Here is my situation. I am using a MVC application (e.g. Joomla or Drupal) which has a .htaccess redirect rule that all requests are passed through index.php file. That's normal and this is my main application. Now I installed another application within the application folder structure. What I want do do here is to allow opening the third party application URLs after one logged into my main application. Can anybody provide me some pointers to do the same? Please let me know if you need any further information on this. Any solution irrespective of framework will work. Thanks! Anupam 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? 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? 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 Code: [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 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 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=317329.0 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? 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. 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 Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=354638.0 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; } 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 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 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! |