发信人: mmcfan(Catch)
整理人: dalasthunder(2002-09-11 15:34:52), 站内信件
|
【 在 yyy8959 的大作中提到:】
:我刚刚学习PHP,最近写了一个BBS,用php语言写的,可是现在发现了一个问题,就是发表的内容都是以网页的形式显示.这就有了一个很大的问题,
: <td width="43%"><textarea rows="7" name="message" cols="42"></textarea> 在此输入内容,
:print"<td width=100% colspan=4 height=35 valign=top> $re[message]</td>"; 在此显示内容
:现在有一些人捣蛋,在内容里面粘贴的是一些网页的源代码,于是显示出来的就是网页了,而不是它的本来内容.
:我想求助的就是:如果内容输入的是什么,就应该显示什么,如果输入的是网页的源代码,也应该显示的是源代码.
:......
// $document should contain an HTML document.
// This will remove HTML tags, javascript sections
// and white space. It will also convert some
// common HTML entities to their text equivalent.
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip out html tags
"'([\r\n])[\s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace html entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // evaluate as php
$replace = array ("",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$text = preg_replace ($search, $replace, $document);
---- 我常喜欢独自一人凝望天空,寻找那种纯净,清雅的蓝色-蓝天,我爱蓝色,大自然把这么美好的色彩赐给天空和大海,它们有多幸运.....!!!
我的EMAIL:[email protected]
我的QQ:733680
我的ICQ:56401685 |
|