bbcode

Preg_replace BBCode Link

痞子三分冷 提交于 2019-12-01 08:12:04
I have this bbcode: [url=http://www.youtube.com/watch?v=h1bIEK1h150]If I offer you my soul[/url] for example. How can I turn this into this: <a href="http://www.youtube.com/watch?v=h1bIEK1h150" target="_blank">If I offer you my soul</a> You need a regular expression. Taking into account that bbcode can have a text URL or only the URL, you will need two statements: $message = preg_replace('@\[url=([^]]*)\]([^[]*)\[/url\]@', '<a href="$1">$2</a>', $message); $message = preg_replace('@\[url\]([^[]*)\[/url\]@', '<a href="$1">$1</a>', $message); Also, if you're parsing bbcode from PHPBB, it can

Preg_replace BBCode Link

坚强是说给别人听的谎言 提交于 2019-12-01 08:02:13
问题 I have this bbcode: [url=http://www.youtube.com/watch?v=h1bIEK1h150]If I offer you my soul[/url] for example. How can I turn this into this: <a href="http://www.youtube.com/watch?v=h1bIEK1h150" target="_blank">If I offer you my soul</a> 回答1: You need a regular expression. Taking into account that bbcode can have a text URL or only the URL, you will need two statements: $message = preg_replace('@\[url=([^]]*)\]([^[]*)\[/url\]@', '<a href="$1">$2</a>', $message); $message = preg_replace('@\[url

bbcode unparser regex help

本秂侑毒 提交于 2019-12-01 01:04:18
I have this function to parse bbcode -> html: $this->text = preg_replace(array( '/\[b\](.*?)\[\/b\]/ms', '/\[i\](.*?)\[\/i\]/ms', '/\[u\](.*?)\[\/u\]/ms', '/\[img\](.*?)\[\/img\]/ms', '/\[email\](.*?)\[\/email\]/ms', '/\[url\="?(.*?)"?\](.*?)\[\/url\]/ms', '/\[size\="?(.*?)"?\](.*?)\[\/size\]/ms', '/\[youtube\](.*?)\[\/youtube\]/ms', '/\[color\="?(.*?)"?\](.*?)\[\/color\]/ms', '/\[quote](.*?)\[\/quote\]/ms', '/\[list\=(.*?)\](.*?)\[\/list\]/ms', '/\[list\](.*?)\[\/list\]/ms', '/\[\*\]\s?(.*?)\n/ms' ),array( '<strong>\1</strong>', '<em>\1</em>', '<u>\1</u>', '<img src="\1" alt="\1" />', '<a

Regex & BBCode - Perfecting Nested Quote

自闭症网瘾萝莉.ら 提交于 2019-11-30 15:59:10
I'm working on some BBcode for my website. I've managed to get most of the codes working perfectly, however the [QUOTE] tag is giving me some grief. When I get something like this: [QUOTE=1] [QUOTE=2] This is a quote from someone else [/QUOTE] This is someone else quoting someone else [/QUOTE] It will return: > 1 said: [QUOTE=2]This is a quote from > someone else This is someone else quoting someone else[/QUOTE] So what is happening is the [/quote] from the nested quote is closing the quote block. The Regex I am using is: "[quote=(.*?)\](.*?)\[/quote\]'is" How can I make it so nested Quotes

Strip BBCode via RegEx

醉酒当歌 提交于 2019-11-30 09:52:43
问题 I am trying to setup a regex that will detect [quote]???[/quote] and will remove it. This is what I have but it is not working: $post['body'] = preg_replace("/\[quote\](.+?)\[\/quote\]/is", '', $post['body']); Can anyone point me in the right direction? I also want to remove any line brakes before or after the [quote]???[/quote]. 回答1: Here's my test with your script: $text = "I am trying to setup a regex that will detect [quote]???[/quote] and will remove it.\r\nThis is what I have but it is

PHP/Regex: simple regex for bbcode [s] or [strike] fails to work

Deadly 提交于 2019-11-29 23:29:52
问题 For a silly bbcode parser I wanted to add two definitions into one, my original definition was this for preg_replace: '#\[s\](.*?)\[/s\]#si', '<strike>\\1</strike>' And this works, I wished for the user to be able to use either [s] or [strike] to initiate text in that format, so I naturally added something like this thinking it would work: '#\[(s|strike)\](.*?)\[/(s|strike)\]#si', '<strike>\\1</strike>' Unfortunately that fails, instead of what you would expect, both [s] and [strike] (used

What markup language for richly formatted content?

我只是一个虾纸丫 提交于 2019-11-29 07:46:10
问题 When you are developing a web-based application and you want to allow richly formatted text from the user you have to make a choice about how to allow that input. Many different markup languages have been created because it is arguably more difficult to sanitize HTML. What are the advantages and disadvantages of the various different markup languages like: HTML Markdown BBCode Textile MediaWiki markup other Or to put it differently, what factors do you consider when choosing to use a

BB-Code-RegEx in javascript

自作多情 提交于 2019-11-28 14:38:08
I have this piece of code: var s_1 = 'blabla [size=42]the answer[/size] bla bla blupblub'; var s_2 = 'blabla [size=42]the answer[/size] bla bla blupblub [size=32] 32 [/size]'; alert('Test-String:\n' + s_1 + '\n\nReplaced:\n' + size(s_1)); alert('Test-String:\n' + s_2 + '\n\nReplaced:\n' + size(s_2)); function size(s) { var reg = /\[size=(\d{1,2})\]([\u0000-\uFFFF]+)\[\/size\]/gi; s = s.replace(reg, function(match, p1, p2) { return '<span style="font-size: ' + ((parseInt(p1) > 48) ? '48' : p1) + 'px;">' + p2 + '</span>'; }) return s; } It's supposed to replace all occurrences of the "[size=nn][

Is there a solid BB code parser for PHP with no dependencies? [closed]

假装没事ソ 提交于 2019-11-28 14:14:22
I've got a situation where the client is using php4 and doesn't look like they have PEAR. Is there an established PHP BBCode parser that will work with vBulletin's BBCode system? I just need to convert the BBCode to HTML. This is a data migration from vBulletin to a new platform, so I can't use vBulletin's BBCode parser. Docs: http://www.vbulletin.com/forum/misc.php?do=bbcode Here's one on HotScripts.com. Update to respond to the criticism (entered three years after you accepted this answer) that this didn't contain enough content directly in the post. The name of the script is currently

Recursive BBCode Parsing

北慕城南 提交于 2019-11-28 09:56:18
问题 I'm trying to parse BBCode in my script. Now, it works seamelessly, until I try to indent BBCode that's more than just bold or underline - such as spoiler, url, font size, etc. - then it screws up. Here's my code: function parse_bbcode($text) { global $db; $oldtext = $text; $bbcodes = $db->select('*', 'bbcodes'); foreach ($bbcodes as $bbcode) { switch ($bbcode->type) { case 'simple': { $find = '{content}'; $replace = '${1}'; $text = preg_replace( '/\['.$bbcode->tag.'\](.+)\[\/'.$bbcode->tag.'