且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从字符串中删除html标签 - 但留下一些

更新时间:2023-11-14 10:30:34

diablo于2005年7月1日在microsoft.public.inetserver.asp.general上写道:
diablo wrote on 01 jul 2005 in microsoft.public.inetserver.asp.general:
我见过几个例子(特别是博客)

http://www.lastkissed.com/?p = 7#comments

将html放入textarea似乎在
的另一面被剥离了。并保留了一些...

例如上面 - 我放了一个< / table>进入评论和
提交 - < blockquote>作为一个块引用出来,但
< / table>好像已经消失了。

有没有办法可以做一个类似的盒子 - 也就是说,如果有人把
html放入其中 - 它会被删除?
i have seen several examples (blogs in particular)

http://www.lastkissed.com/?p=7#comments

where placing html into a textarea seems to be stripped out on the
other side. and yet retains some...

for example the above - i placed a </table> into the comment and
submitted - the <blockquote> came out as a block quote but the
</table> seems to have dissappeared.

is there a way i can do a similar box - ie so that if someone puts
html into it - it is stripped out?

>

在ASP Jscript中:


<%

myString = myString.replace(/< [^>] *> / g,'''');

%>


-

Evertjan。

荷兰。

(用我的电子邮件地址替换所有带点的十字架)



In ASP Jscript:

<%
myString = myString.replace(/<[^>]*>/g,'''');
%>

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)


你怎么会遗漏,比方说,< img和< a标签,所以你可以允许

超链接和img引用,但没有别的吗?
How would you leave out, say, <img and <a tags, so you could allow
hyperlinks and img references but nothing else?
在ASP Jscript中:

<%
myString = myString.replace(/< [^>] *> / g,'''');
%>
In ASP Jscript:

<%
myString = myString.replace(/<[^>]*>/g,'''');
%>



Foo Man Chew于2005年7月1日在

microsoft.public.inetserver.asp.general写道:
Foo Man Chew wrote on 01 jul 2005 in
microsoft.public.inetserver.asp.general:
在ASP Jscript中:

& lt;%
myString = myString.replace(/< [^>] *> / g,'''');
%>
In ASP Jscript:

<%
myString = myString.replace(/<[^>]*>/g,'''');
%>



[请不要使用usenet]

你怎么会遗漏,比如说< img和<一个标签,所以你可以允许
超链接和img引用,但没有别的?


[please do not toppost on usenet]
How would you leave out, say, <img and <a tags, so you could allow
hyperlinks and img references but nothing else?




我想:


myString = myString.replace(/< img / ig,''%% %img'');

myString = myString.replace(/< a / ig,''%%% a'');

myString = myString.replace (/< \ / a> / ig,''%%% / a>'');

myString = myString.replace(/< [^>] *> / g,'''');


myString = myString.replace(/ %%% / g,''<'');


没有测试!


然而,这不会保留行尾< a,< img。

Inline''%% %''字符串需要被阻止。

但是,由于这不是一个pais帮助热线,我把它留给你的专业知识。


-

Evertj a。

荷兰。

(用我的电子邮件地址替换所有带点的十字架)



I would think:

myString = myString.replace(/<img /ig,''%%%img '');
myString = myString.replace(/<a /ig,''%%%a '');
myString = myString.replace(/<\/a>/ig,''%%%/a>'');
myString = myString.replace(/<[^>]*>/g,'''');

myString = myString.replace(/%%%/g,''<'');

NOT TESTED!

However this would not keep an end-of-line <a, <img.
Inline ''%%%'' strings need to be prevented.
But, as this is not a pais helpline, I leave that to your expertise.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)