<div class="pic_news">
<div id="focusViwer" align="center">
<embed id="focusflash" width="320" height="225" flashvars='<%=FULL %>'
wmode="opaque" menu="false" allowscriptaccess="sameDomain" quality="High" bgcolor="#F5F5F5"
name="focusflash" src="images/flash1.swf" type="application/x-shockwave-flash">
</div>
<script type="text/javascript" charset="gbk">
<!--
var focus_width = 318
var focus_height = 218
var text_height = 25
var swf_height = focus_height + text_height
var pics = '<%=PICURL %>';
var links = '<%=LINKS %>';
links = links.replace(/.$/, "");
var texts = '<%=TEXT %>';
var FocusFlash = new sinaFlash("images/flash1", "focusflash", focus_width, swf_height, "7", "#F5F5F5", false, "High");
FocusFlash.addParam("allowScriptAccess", "sameDomain");
FocusFlash.addParam("menu", "false");
FocusFlash.addParam("wmode", "opaque");
FocusFlash.addVariable("pics", pics);
FocusFlash.addVariable("links", links);
FocusFlash.addVariable("texts", texts);
FocusFlash.addVariable("borderwidth", focus_width);
FocusFlash.addVariable("borderheight", focus_height);
FocusFlash.addVariable("textheight", text_height);
FocusFlash.write("focusViwer");
//-->
</script>
</div>
OracleDM dm = new OracleDM();
public string LINKS = ""; //超链接
public string PICURL = ""; //图片路径
public string TEXT = ""; //文本
public string FULL = ""; //全路径
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RpTzgg();//通知公告
RpXwlb();//新闻列表
RpQxsl();//区县水利
RpZtbd();//专题报道
RpFxkh();//防汛抗旱
RpSzjc(); //水政监察
ShowIMG();//生成图片报道
}
}
//首页图片新闻
public void ShowIMG()
{
string sqlstr = " select ID, TITLE , L_Content from (select * from t_leastclass where type='图片报道' ) where rownum<=5";
DataTable dtP = dm.getsql(sqlstr).Tables[0];
string strTitle = "";//拼接标题
string picUrl = ""; //图片标题
string link = ""; //超链接
for (int i = 0; i < dtP.Rows.Count; i++)
{
strTitle += dtP.Rows[i]["TITLE"].ToString().Length > 20 ? dtP.Rows[i]["TITLE"].ToString().Substring(0, 20) + "..." : dtP.Rows[i]["Title"].ToString() + "|";
picUrl += getImageUrl(dtP.Rows[i]["L_CONTENT"].ToString()) + "|";
link += "lashgc.aspx?id=" + dtP.Rows[i]["ID"].ToString() + "|";
}
strTitle = strTitle.TrimEnd('|');
picUrl = picUrl.TrimEnd('|');
link = link.TrimEnd('|');
LINKS = link;
PICURL = picUrl;
TEXT = strTitle;
FULL = "pics=" + PICURL + "&links=" + LINKS + "&texts=" + TEXT + "&borderwidth=320&borderheight=198&textheight=26";
}
/// <summary>
/// 从字符串中获取需要的图片地址
/// </summary>
/// <param name="source">字符串</param>
/// <returns>需要的图片地址</returns>
public string getImageUrl(string source)
{
ArrayList list = new ArrayList();
string result = "";
string pattern = "<img[^<>]*?\\ssrc=['\"]?(.*?)['\"].*?>";
Regex reg = new Regex(pattern);
MatchCollection mc = reg.Matches(source);
foreach (Match m in mc)
{
list.Add(m.Groups[1].Value);
}
if (list.Count > 0)
{
string s = list[0].ToString().TrimStart('/');
result = s.Substring(s.IndexOf('/') + 1);
}
else
{
result = "images/noPic.jpg";
}
return result;
}
#endregion
重点是:利用正则表达式取字符串中的图片路径
<img[^<>]*?\\ssrc=['\"]?(.*?)['\"].*?>