zoukankan      html  css  js  c++  java
  • 正则表达式

                //匹配图片
                var regexImg = new Regex(@"<img (.*?)src=(.[^[^>]*)(.*?)>", RegexOptions.IgnoreCase);
                var matches = regexImg.Matches(editor1.BodyHtml);
                var ftp = Common.NewsFtp(true);
                //遍历每个图片
                foreach (Match match in matches)
                {
                    string localPath = match.Value;
                    //匹配地址
                    var regex = new Regex("src="(.*)">");
                    var matchLocal = regex.Match(localPath);
                    if (matchLocal.Success)
                    {
                        string str = matchLocal.Groups[1].Value;
                        if (File.Exists(str))
                        {
                            var fileInfo = new FileInfo(str);
                            string dir = Path.GetDirectoryName(str);
                            string ext = Path.GetExtension(str);
                            string path = dir + "\" + Guid.NewGuid() + ext;
                            fileInfo.MoveTo(path);
                            try
                            {
                                ftp.UploadFile(path, "");
                                string s = BasePath.ContentImagesAbsoluteURI +
                                           Path.GetFileName(path);
                                string detail = t.NewsDetail;
                                detail = detail.Replace(str, s);
                                t.NewsDetail = detail;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                                return;
                            }
                        }
                    }
                }

  • 相关阅读:
    防F12审查元素扒代码:按下F12关闭当前页面
    Wp-UserAgent——让WordPress在评论后面加上浏览器和操作系统信息
    WordPress中添加自定义评论表情包的方法
    WordPress彩色背景标签云实现
    让wordpress标签云显示文章数的正确方法
    如何在WordPress文本小工具中使用PHP
    WordPress非插件实现评论回复邮件提醒通知
    Firefox取消“订阅实时书签”功能
    WordPress修改标签云大小及颜色
    WordPress菜单“显示选项”无法显示的解决办法
  • 原文地址:https://www.cnblogs.com/EDSON/p/3357620.html
Copyright © 2011-2022 走看看