从字符串中删除html标签 - 但留下一些 [英] removin html tags from string - but leaving a few behind

查看:68
本文介绍了从字符串中删除html标签 - 但留下一些的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




i见过几个例子(特别是博客)

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


放置的位置html进入textarea似乎被剥夺了另一方

方面。然而保留了一些...


例如以上 - 我放了一个< / table>进入评论并提交 -

< blockquote>以块引用形式出现,但< / table>似乎已经消失了




有没有办法可以做类似的盒子 - 也就是说,如果有人把html放入

it - 它被剥离了吗?


感谢您的帮助


暗黑破坏神

hi

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?

thanks for help

Diablo

推荐答案

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)


这篇关于从字符串中删除html标签 - 但留下一些的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆