首页 > 代码库 > iOS -- 转义html中的标签

iOS -- 转义html中的标签

#pragma mark -- 转义html中的标签

- (NSString *)HTML:(NSString *)html

{

    NSScanner *theScaner = [NSScanner scannerWithString:html];

    NSDictionary *dict = @{@"&amp;":@"&", @"&lt;":@"<", @"&gt;":@">", @"&nbsp;":@"", @"&quot;":@"\"", @"width":@"wid"};

    while ([theScaner isAtEnd] == NO) {

        for (int i = 0; i <[dict allKeys].count; i ++) {

            [theScaner scanUpToString:[dict allKeys][i] intoString:NULL];

            html = [html stringByReplacingOccurrencesOfString:[dict allKeys][i] withString:[dict allValues][i]];

        }

    }

    return html;

}

iOS -- 转义html中的标签