in some small forums or small comment systems, the term "support UBB" is often encountered. In fact, the UBB code is a variant of HTML, customizing our labels through programs, such as "[/a] in UBB in [a] PHP". The essence of it is to use technology to find [a][/a] tags and replace them into.Lt; a.gt;.Lt; /a.gt; the standard HTML. It is to say that the standard HTML markup is simplified by technical means, and the output result is a standard HTML.
understand the principle of UBB, so it is not difficult to make a simple UBB editor. Compared with fck such as fck, the biggest advantage of UBB code is that the code is simple, the function is very few, the simple UBB only needs one file, and the UBB label can be defined by itself, and the change is very square. Then, in PHP is the use of substitution function can be used to label HTML, the output of the transformation of the label, the following is a PHP UBB source code, only one file, the implementation of the UBB editor, there are many varieties of UBB code on the network, the core principle is basically the same.
the novel shows that the HTML of the actual standard of [a]http://www.60ie.net[/a] is.Lt; a href=http://www.60ie.net.Gt; http://www.60ie.net.lt; /a.gt; UBB editor. The label, the code is not a lot of simplicity.
PHP simple UBB interface Preview:
[code].lt; php
/*
* To change. /.#91; a.#93;.#91; /a.#93; hyperlinked
$str=preg_replace (.Quot; /\.#91; a\.#93; *) \.#91; \/a\.#93; /i.quot. K\.quot; href=\.quot; tencent://message/? Uin=\${1}.amp; site=www.60ie.net.amp; menu=yes\.quot;.Gt;.Lt; img src=\.quot; http://wpa.qq.com/pa p=1:\${1}. 93; hyperlink
$str=preg_replace (.Quot; /\.#91; img\.#93; (*?) \.#91; \/img\.#93; /i.quot;.Quot;.Lt; img src=\\1. TTAG (TOpen, tclose) {
var themess = document.getElementById ('test'); / / / edit object
themess.focus ();
if. Ction) {
document.selection.createRange ().Text = theSelection = TOpen theSelection tclose; / / / / / / >}else{
document.selection.createRange ().Text = =; Var selLength = themess.textLength;
var selStart = themess.selectionStart; / / / / selection start point index, not selected as 0
var selEnd = themess.selectionEnd; / / / / selection end point index
= = 2);
var S2 = (themess.value).Substring (selStart, selEnd) / / / / / / > var S3 = (themess.value).Substring (themess.value);
themess.selectionStart = newStart;
themess.selectionEnd = newStart;
themess.scrollTop = scrollPos;
return;
.Lt; form action=.quot;.Quot; method=.quot; post.quot;.Gt;
. Lick='inserttag (.Quot;.#91; qq.#93;.Quot;.Quot;.#91; /qq.#93;.Quot;'.gt;'.gt; the addition of QQ label.Lt). Test.quot; name=.quot; text.quot; rows=.quot; 10.quot; cols=.quot; 50.quot; wrap=.quot; off.quot;.Gt;.Lt; /textarea.gt; subordinate.