【Vegas原创】用正则表达式解决FCKEditor图片路径问题
2008-05-21 17:02
597 查看
在用FCKEditor发邮件时,正文中图片会显示不出来,因为它默认路径是userfiles/images/*.jpg,如下
<input type="image" height="131" width="139"
src="/userfiles/image/_W@S2WETFST%25F%25Z21AQCI3P.JPG" />
怎么转换为:
<input type="image" height="131" width="139" src="\\[Server]\userfiles\image\_W@S2WETFST%25F%25Z21AQCI3P.JPG" />
asp解法:
'邮件正文
strsql="select txt,Filename,File_Name from bbs where unique_id="+Request.QueryString("Unique_ID")
set rs=connection.execute(strsql)
myTxt = rs("txt")
'利用正则表达式替换img标记
dim objRe
set objRe = New RegExp
'設定正則式
objRe.Pattern = "(src=)('|"&CHR(34)&"| )?(.[^'| |"&CHR(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)('|"&CHR(34)&"| |>)?"
objRe.IgnoreCase = true
objRe.Multiline = true
objRe.Global = true
set matches = objRe.Execute(myTxt)
newtxt = myTxt
for each match in matches
cccc = split(match.value,"/")
if(ubound(cccc) <> 0) then
'获得应该的字符串
for i=0 to ubound(cccc)
if i = 0 then
mystr = cccc(0)&"\\[server]\"
else if i= ubound(cccc) then
mystr = mystr&cccc(i)
else
mystr = mystr&cccc(i)&"\"
end if
end if
next
newtxt = Replace(newtxt,match.value,mystr)
end if
next
set objRE = nothing
a = "<body background='\\[server]\2008back.gif'>"
Body=a& newtxt &"</body>"
====================================================================
.Net 解法:
using System.Text.RegularExpressions;
string convertExp(string strTxt)
{
string strPattern = "(src=)('|" + (char)34 + "| )?(.[^'| |" + (char)34 + "]*)(\\.)(jpg|gif|png|bmp|jpeg)('|" + (char)34 + "| |>)?";
// Compile the regular expression.
Regex objRe=new Regex(strPattern);
// Match the regular expression pattern against a text string.
MatchCollection matches=objRe.Matches(strTxt);
string mystr="";
string strNewTxt = strTxt;
foreach (Match match in matches)
{
string[] strC = match.Value.Split('/');
//if it's the bottom jpg,break Foreach
if (strC[strC.Length - 1].ToString() == "asdf.jpg\"")
{
break;
}
if (strC.Length != 0)
{
for (int i = 0; i < strC.Length; i++)
{
if (i == 0)
mystr = strC[0] + "\\\\[server]\\";
else if (i == strC.Length - 1)
mystr = mystr + strC[i];
else
mystr = mystr + strC[i] + "\\";
}
strNewTxt = strNewTxt.Replace(match.Value, mystr);
}
}
return strNewTxt;
}
调用:
StringBuilder sb = getMailContent(strSubject);
lblPreview.Text = convertExp(sb.ToString());
<input type="image" height="131" width="139"
src="/userfiles/image/_W@S2WETFST%25F%25Z21AQCI3P.JPG" />
怎么转换为:
<input type="image" height="131" width="139" src="\\[Server]\userfiles\image\_W@S2WETFST%25F%25Z21AQCI3P.JPG" />
asp解法:
'邮件正文
strsql="select txt,Filename,File_Name from bbs where unique_id="+Request.QueryString("Unique_ID")
set rs=connection.execute(strsql)
myTxt = rs("txt")
'利用正则表达式替换img标记
dim objRe
set objRe = New RegExp
'設定正則式
objRe.Pattern = "(src=)('|"&CHR(34)&"| )?(.[^'| |"&CHR(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)('|"&CHR(34)&"| |>)?"
objRe.IgnoreCase = true
objRe.Multiline = true
objRe.Global = true
set matches = objRe.Execute(myTxt)
newtxt = myTxt
for each match in matches
cccc = split(match.value,"/")
if(ubound(cccc) <> 0) then
'获得应该的字符串
for i=0 to ubound(cccc)
if i = 0 then
mystr = cccc(0)&"\\[server]\"
else if i= ubound(cccc) then
mystr = mystr&cccc(i)
else
mystr = mystr&cccc(i)&"\"
end if
end if
next
newtxt = Replace(newtxt,match.value,mystr)
end if
next
set objRE = nothing
a = "<body background='\\[server]\2008back.gif'>"
Body=a& newtxt &"</body>"
====================================================================
.Net 解法:
using System.Text.RegularExpressions;
string convertExp(string strTxt)
{
string strPattern = "(src=)('|" + (char)34 + "| )?(.[^'| |" + (char)34 + "]*)(\\.)(jpg|gif|png|bmp|jpeg)('|" + (char)34 + "| |>)?";
// Compile the regular expression.
Regex objRe=new Regex(strPattern);
// Match the regular expression pattern against a text string.
MatchCollection matches=objRe.Matches(strTxt);
string mystr="";
string strNewTxt = strTxt;
foreach (Match match in matches)
{
string[] strC = match.Value.Split('/');
//if it's the bottom jpg,break Foreach
if (strC[strC.Length - 1].ToString() == "asdf.jpg\"")
{
break;
}
if (strC.Length != 0)
{
for (int i = 0; i < strC.Length; i++)
{
if (i == 0)
mystr = strC[0] + "\\\\[server]\\";
else if (i == strC.Length - 1)
mystr = mystr + strC[i];
else
mystr = mystr + strC[i] + "\\";
}
strNewTxt = strNewTxt.Replace(match.Value, mystr);
}
}
return strNewTxt;
}
调用:
StringBuilder sb = getMailContent(strSubject);
lblPreview.Text = convertExp(sb.ToString());
相关文章推荐
- 【Vegas原创】用正则表达式解决FCKEditor图片路径问题
- 【Vegas原创】用正则表达式解决FCKEditor图片路径问题
- FCKeditor编辑器添加图片上传功能及图片路径问题解决方法
- 日期正则表达式(解决闫月问题)
- C#正则表达式匹配HTML中的图片路径
- PHP用正则批量替换Img中src内容,用正则表达式获取图片路径实现缩略图功能
- HBase中正则过滤表达式与JAVA正则表达式不一致问题的分析和解决
- 【android学习】通过正则表达式解决数据传输过程中的堆包问题
- 用正则表达式截取数据库中img图片路径的方法
- FCKEditor 2.6.3 ASP.NET 图片上传 停留在进度条问题解决
- Android开发——相册拍照_03.解决相机拍照之后部分手机无法将图片保存到路径或部分手机点击相机确定无法返回问题
- 解决C:\fakepath路径加密问题,图片上传之前的预览功能的实现,html5 实现图片预览功能
- asp.net+FCKeditor上传图片显示叉叉图片无法显示的问题的解决方法
- 解决jsp页面使用网络路径访问图片的乱码问题
- DedeCMS系统自定义字段图片类型调用的路径问题解决办法.doc
- paip.解决中文url路径的问题图片文件不能显示
- 解决android4.4以上获取不到图片路径问题
- 【Java】Java根据路径获取图片偶尔会得不到图片问题的解决方法
- 正则表达式获取网页中所有图片的路径
- SSM框架中引入css,js,图片文件的路径问题解决