The following code is a method of character replacement, not a regular expression Function content_Code(Str)
dim ary_String,i,n,n_pos
ary_String=split(Str,[code])
n=ubound(ary_String)
If n<1 then
content_Code=Str
Exit function
End If
for i=1 to n
n_pos=inStr(ary_String(i),[/ code ])
If n_pos>0 then
ary_String(i)=<br /><textarea class=gocode id=runcode&i& name=runcode&i&> & server.HTMLEncode(left(ary_String(i),n_pos-1))&</textarea><br /><input type =button class=input-code value=Run code onclick=runCode(runcode&i&)><input type=button class=input-code value=Copy code onclick=copycode(runcode&i&)><input type=button class=input-code value=Save code onclick=saveCode(runcode&i&)><span class=code-tishi>Tip: You can modify part of the code before running it </span><br /> & _
right(ary_String(i),len(ary_String(i))-n_pos-6)
Else
ary_String(i)=[code] & ary_String(i)
End if
next
content_Code=join(ary_String,)
End Function
The usage is also very simple:
When publishing an article, you need to use the running code function. Mainly add
[ code ][/ code ]
for example:
[Copy this code]CODE:
[code]
<script type=text/javascript>
alert(simple);
</script>
[/code]
It should be noted that the following javascript must be entered on the displayed page:
function runCode(obj) {
var winname = window.open('', _blank, '');
winname.document.open('text/html', 'replace');
winname.opener = null
winname.document.writeln(obj.value);
winname.document.close();
}
function copycode(obj) {
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand(Copy);
rng.collapse(false);
}
function saveCode(obj) {
var winname = window.open('', '_blank', 'top=10000');
winname.document.open('text/html', 'replace');
winname.document.write(obj.value);
winname.document.execCommand('saveas','','code.htm');
winname.close();
}