重写html代码当中的img标签内容,图片地址不变

这个东西是我找了老长时间然后拼凑起来的,希望大家能用上

public static string GetImgUrl(string content, int height, int width)
    {
        string ps = @"<img/s+[^>]*src/s*=/s*(?:""(?<url>[^""]*)""|'(?<url>[^']*)'|(?<url>[^>^/s]+)).*?>";
        Regex reg = new Regex(ps, RegexOptions.IgnoreCase);
        for (Match m = reg.Match(content); m.Success; m = m.NextMatch())
        {
            content = content.Replace(m.Groups[0].ToString(), "<img src=/"" + m.Groups["url"].ToString() + "/" border=/"0/" onload=/"changeImg(this," + height + "," + width + ")/">");
        }
        return content;
    }

说点什么

avatar
  Subscribe  
提醒