如何让数据库中内容在网页中按格式输出
最近在学习做动态网页,遇到了个问题,很久没有解决的办法,就是从数据库中读出的内容在网页中输出是原来的空格和段落换行的格式都没有了,整个就成了一段了,我在网上也查了些资料,...
最近在学习做动态网页,遇到了个问题,很久没有解决的办法,就是从数据库中读出的内容在网页中输出是原来的空格和段落换行的格式都没有了,整个就成了一段了,我在网上也查了些资料,说是changechr(str)这个函数可以解决,我试了很多次,还是不会用,哪为高手能指点下,本人感激不尽,这是我的一个简单输出的网页代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/a.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_a_STRING
Recordset1.Source = "SELECT * FROM liuyanban ORDER BY id DESC"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = 10
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<table width="768" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="139" rowspan="2" valign="top"><img src="image/sg803_index_30.jpg" width="178" height="435"></td>
<td width="629" height="74" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="629" height="116" valign="top"><img src="image/sg803_index_16.jpg" width="628" height="211"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="308" valign="top"><%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<table width="579" height="66" border="1">
<tr>
<td>姓名:<%=(Recordset1.Fields.Item("name").Value)%></td>
</tr>
<tr>
<td>内容:<%=(Recordset1.Fields.Item("content").Value)%></td>
</tr>
<tr>
<td bgcolor="#0000CC"> </td>
</tr>
</table>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%></td>
</tr>
</table>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%> 展开
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/a.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_a_STRING
Recordset1.Source = "SELECT * FROM liuyanban ORDER BY id DESC"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = 10
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<table width="768" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="139" rowspan="2" valign="top"><img src="image/sg803_index_30.jpg" width="178" height="435"></td>
<td width="629" height="74" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="629" height="116" valign="top"><img src="image/sg803_index_16.jpg" width="628" height="211"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="308" valign="top"><%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<table width="579" height="66" border="1">
<tr>
<td>姓名:<%=(Recordset1.Fields.Item("name").Value)%></td>
</tr>
<tr>
<td>内容:<%=(Recordset1.Fields.Item("content").Value)%></td>
</tr>
<tr>
<td bgcolor="#0000CC"> </td>
</tr>
</table>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%></td>
</tr>
</table>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%> 展开
2个回答
2015-08-11 · 知道合伙人数码行家
关注
展开全部
解决代码如下:
/// <summary>
/// 转换关键字符
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string ReplaceKeyChar(string str)
{
str = str.Replace("'","’");
str = str.Replace("<","<");
str = str.Replace(">",">");
str = str.Replace("\n","<br>");
return str;
}
/// <summary>
/// 转换关键字符
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string ReplaceKeyChar(string str)
{
str = str.Replace("'","’");
str = str.Replace("<","<");
str = str.Replace(">",">");
str = str.Replace("\n","<br>");
return str;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询