IOS中过滤HTML标签


 1 - (void)dooo  
 2 {  
 3       
 4     NSLog(@"------");  
 5     NSString * str=@"<p style=\"text-align: center;\"><img style=\"width:94%;height:auto\" src=\"http://p1.img.cctvpic.com/photoworkspace/contentimg/2014/01/13/2014011318535072073.jpg\" alt=\"访美首站为西雅图将参观波音和微软\" width=\"500\"/></p><p style=\"text-align: center;\"><span style=\"color: #0000ff;\"><strong>AC米兰官方宣布阿莱格里下课</strong></span></p><p><span style=\"color: #000000;\">  北京时间1月13日晚6时,意甲AC米兰俱乐部官方宣布主帅阿莱格里下课。昨天的意甲第19轮比赛中,AC米兰客场3比4不敌升班马萨索洛,比赛结束之后就传出了阿莱格里将会被解雇的消息。</span></p><p><span style=\"color: #000000;\">  米兰的官方公告中写道:“阿莱格里先生和他的助手们将不再担任球队一线队教练的工作,对此我们非常遗憾,感谢阿莱格里和他的团队几年来为俱乐部做出的贡献,祝愿他在未来的工作中继续取得成功。”<span style=\"font-size: 14px;\">此前意大利方面的消息都是在阿莱格里下课后,前米兰球星因扎吉将暂时接手球队,不过米兰官方公告中称球队的训练和比赛任务暂时由助理教练毛罗-塔索蒂负责。</span></span></p><p><span style=\"color: #000000;\">  <span style=\"font-size: 14px;\">阿莱格里在2010年世界杯后上任成为AC米兰队主教练,带队第一个赛季就帮助米兰七年后重夺意甲联赛冠军,随后又率队在北京击败国米夺得意大利超级杯,第二个赛季米兰战绩同样不错,可惜在关键一战中因为裁判的误判失去了一个重要进球,米兰在联赛冠军的争夺中输给了尤文图斯,后面两个赛季米兰阵容人员不整,不过阿莱格里还是率队赢得了上赛季的第三名,从而获得本赛季欧冠参赛资格。新赛季米兰战绩比上赛季还差,主帅阿莱格里终于被解职。</span></span></p>";  
 6   
 7     [self flattenHTML:str];  
 8   
 9 }
10 - (NSString *)flattenHTML:(NSString *)html {  
11       
12     NSScanner *theScanner;  
13     NSString *text = nil;  
14       
15     theScanner = [NSScanner scannerWithString:html];  
16       
17     while ([theScanner isAtEnd] == NO) {  
18         // find start of tag  
19         [theScanner scanUpToString:@"<" intoString:NULL] ;  
20         // find end of tag  
21         [theScanner scanUpToString:@">" intoString:&text] ;  
22         // replace the found tag with a space  
23         //(you can filter multi-spaces out later if you wish)  
24         html = [html stringByReplacingOccurrencesOfString:  
25                 [NSString stringWithFormat:@"%@>", text]  
26                                                withString:@""];  
27     } // while //  
28       
29     NSLog(@"-----===%@",html);  
30     return html;  
31 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM