我需要一个正则表达式来去除字符串中的任何 BBCode。我有以下内容(以及带有标签的数组):
new RegExp('\\[' + tags[index] + '](.*?)\\[/' + tags[index] + ']');
Run Code Online (Sandbox Code Playgroud)
它可以很好地拾取 [tag]this[/tag] ,但在使用 [url= http://google.com]this[/url]时失败。
我需要改变什么?多谢。
我有这个bbcode:
[url=http://www.youtube.com/watch?v=h1bIEK1h150]If I offer you my soul[/url]
Run Code Online (Sandbox Code Playgroud)
例如.我怎么能把它变成这个:
<a href="http://www.youtube.com/watch?v=h1bIEK1h150" target="_blank">If I offer you my soul</a>
Run Code Online (Sandbox Code Playgroud) 什么是处理简单文本样式的最佳方式,如bbcode允许在文本内部加粗斜体等?我所做的是将文本分成几部分,每个部分都分配了样式,然后我从每个部分开始发短信Rect.Left + Canvas.TextWidth(Texts[i-1]).然而,这可能非常慢,而且我不知道如何在VirtualStringTree的情况下发布它.它具有OnBeforeItemPaint,但回调不知道列索引.然而OnBeforeCellPaint并没有公开变量来说我自己绘制的VST,因此它描绘了我的文字......
有人吗?:)
问候,米哈尔
我有一种情况,客户端使用php4,看起来他们没有PEAR.是否有一个已经建立的PHP BBCode解析器可以与vBulletin的BBCode系统一起使用?
我只需要将BBCode转换为HTML.这是从vBulletin到新平台的数据迁移,因此我无法使用vBulletin的BBCode解析器.
文档:
我试图在随机文本中匹配"url"BB代码标签.示例文字:
Lorem ipsum dolor坐下来,精致的adipistur elit.[url] http://www.google.com [/ url] Donec purus nunc,rhoncus vitae tempus vitae,[url = www.facebook.com] facebook [/ url] elementum sit amet justo.
我想从这段文本中找到两个"url"标签:
[url]http://www.google.com[/url][url=www.facebook.com]facebook[/url]我对正则表达式不太好,所以这是我能得到的:
\[url(=[a-z]*)?\][a-z]*\[/url\]
Run Code Online (Sandbox Code Playgroud)
我想我只需要用匹配任何东西的东西替换[az]除了字符'['和']'之外.有人可以帮我解决这个问题吗?
我有这个函数来解析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 href="mailto:\1">\1</a>',
'<a href="\1">\2</a>',
'<span style="font-size:\1%">\2</span>',
'<object width="450" height="350"><param name="movie" value="\1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="\1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="450" height="350"></embed></object>',
'<span style="color:\1">\2</span>',
'<blockquote>\1</blockquote>',
'<ol start="\1">\2</ol>',
'<ul>\1</ul>',
'<li>\1</li>'
),$original);
Run Code Online (Sandbox Code Playgroud)
问题是,如何解析这个,比如html - > bbcode?
我的正则表达能力很差:(
谢谢.
我目前正在使用PHP和MySql开发游戏.我想让用户能够使用BBCode解析器(NBBC)显示图像,但我已经意识到潜在的安全问题.
请允许我解释一下:
用户使用诸如[img] http://example.com/image1.png [/ img]之类的代码将URL输入到textarea框中
然后,用户可以将外部服务器上的image1.png编辑为存储用户信息(ip ect)等的服务器端脚本.
用户使用信息做一些可能讨厌的东西!
我的问题是,在使用外部资源进行详细设计时,我们如何防止这种情况发生并保护用户详细信息?
显而易见的答案是只允许上传到您的网站,但在这种情况下,这似乎并不太实际.
感谢任何帮助!
我正试图在我的脚本中解析BBCode.现在,它无缝地工作,直到我尝试缩进BBCode不仅仅是粗体或下划线 - 例如剧透,网址,字体大小等 - 然后它搞砸了.这是我的代码:
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.'\]/i',
str_replace($find, $replace, $bbcode->html),
$text);
break;
}
case 'property':
case 'options': {
$find = array ( '{property}', '{content}' );
$replace = array ( '${1}', '${2}' );
$text = preg_replace(
'/\['.$bbcode->tag.'\=(.[^\"]*)\](.+)\[\/'.$bbcode->tag.'\]/i',
str_replace($find, $replace, $bbcode->html),
$text);
break;
}
}
}
return $text;
}
Run Code Online (Sandbox Code Playgroud)
现在我的猜测是RegEx不喜欢模式中的递归.我怎样才能改进它?示例$ bbcode对象是这样的: …
我一直试图在JavaScript中解析bbcode URL标记.
例如,
[url=http://examp.le]linktext[/url]
Run Code Online (Sandbox Code Playgroud)
应该成为
<a href="http://examp.le">linktext</a>.
Run Code Online (Sandbox Code Playgroud)
我对此做了很多研究,并且对正则表达式有了非常深刻的理解.所以问题是,我该怎么做?
我该如何解析php中的url?我想做到这一点
[url=http://www.google.com]Google[/url]
Run Code Online (Sandbox Code Playgroud)
变成:
<a href="http://www.google.com">Google</a>
Run Code Online (Sandbox Code Playgroud)
这是我用于其他bb代码的代码:
function postparser($post){
$post = str_replace("\n",'END_OF_LINE',$post);
$post = str_replace("[line]",'HORIZONTAL_LINE',$post);
$post = str_replace("[bold]",'BOLD_TEXT_START',$post);
$post = str_replace("[/bold]",'BOLD_TEXT_END',$post);
$post = str_replace("[yt]",'YOUTUBE_START',$post);
$post = str_replace("[/yt]",'YOUTUBE_END',$post);
$post = sanitize($post);
$post = str_replace("END_OF_LINE",'<br />',$post);
$post = str_replace("HORIZONTAL_LINE",'<hr />',$post);
$post = str_replace("BOLD_TEXT_START",'<b>',$post);
$post = str_replace("BOLD_TEXT_END",'</b>',$post);
$post = str_replace("YOUTUBE_START",'<iframe width="560" height="315" src="http://www.youtube.com/embed/',$post);
$post = str_replace("YOUTUBE_END",'" frameborder="0" allowfullscreen></iframe>',$post);
return $post;
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?