怎么去掉php标签..

wasg 2004-09-29 12:01:02
一个php文件的内容是用这样的方式显示html的:

mysql_connect($dbhost,$dbuser,$dbpasswd) or die ("数据库连接失败");

$sql = "SELECT * FROM test_table WHERE id=12";
$result = mysql_db_query($dbname, $sql);
$row = mysql_fetch_array($result);
if($show == 1){
echo "<html><head>\n";
echo "<meta http-equiv=Content-Type content=text/html; charset=gb2312>\n";
echo "<meta name=GENERATOR content=Microsoft FrontPage 4.0>\n";
echo "<meta name=ProgId content=FrontPage.Editor.Document>\n";
echo "$row[name]";
}

现在我想用fopen把文件读入一个变量,在把里面的php标签去掉,只留下html,可是找不到,只找到个"strip_tags",可是他是去掉html和php标签的,,,谁有办法吗?
...全文
394 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
CYBEREXP2008 2010-06-02
  • 打赏
  • 举报
回复
/**
* 去掉字符串的html标签
*
* @param string $str 包含html代码的字符串
* @return $text 去掉html标签后的纯洁字符串
*/
function html2txt($str)
{
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);
$text = preg_replace($search, '', $str);
return $text;
}
xuzuning 2004-09-30
  • 打赏
  • 举报
回复
$s = file_get_contents("http://localhost/page.php");
就可得到html代码了
wasg 2004-09-30
  • 打赏
  • 举报
回复
to xuzuning(唠叨):
是我写进去的啊,,可是现在我想过滤掉,把他做成html页面..而不是php.
xuzuning 2004-09-30
  • 打赏
  • 举报
回复
你是说你只要
<html><head>
<meta http-equiv=Content-Type content=text/html; charset=gb2312>
<meta name=GENERATOR content=Microsoft FrontPage 4.0>
<meta name=ProgId content=FrontPage.Editor.Document>
这些吗?
这有什么意义呢?不都是你写进去的吗?
pswdf 2004-09-30
  • 打赏
  • 举报
回复
strip_tags();
wasg 2004-09-30
  • 打赏
  • 举报
回复
呵,没完美的解决方法了,,谢谢大家.
wasg 2004-09-29
  • 打赏
  • 举报
回复
这个正则好像会把中间的东西全部清除掉耶.
screend 2004-09-29
  • 打赏
  • 举报
回复
先将文件读到一个字串,然后
preg_replace('/^<[\\?].*[\\?]>/i','',$o_string);
楼主试试,突然忘记很多正则语法了
wasg 2004-09-29
  • 打赏
  • 举报
回复
谁能介绍个好点的方法啊?
wasg 2004-09-29
  • 打赏
  • 举报
回复
那也是,麻烦啊,,文件有N长啊,,手动的话.......=.=
zairwolfi 2004-09-29
  • 打赏
  • 举报
回复
不懂怎么提取这些html。你如果html里面也有类似php的代码呢?怎么提取?
wasg 2004-09-29
  • 打赏
  • 举报
回复
有谁会吗?

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧