如何编码“&”在HTML属性值的URL中? [英] How do I encode "&" in a URL in an HTML attribute value?
本文介绍了如何编码“&”在HTML属性值的URL中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在电子邮件应用程式中设定可点击的网址。问题是,参数化的URL由于&在URL中。下面的主体变量是问题行。 body的两个版本都不正确。电子邮件应用打开后,文本会停在... link:。需要对和号进行编码吗?
I'd like to make a URL click able in the email app. The problem is that a parameterized URL breaks this because of "&" in the URL. The body variable below is the problem line. Both versions of "body" are incorrect. Once the email app opens, text stops at "...link:". What is needed to encode the ampersand?
NSString *subject = @"This is a test";
NSString *encodedSubject =
[subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//NSString *body = @"This is a link: <a href='http://somewhere.com/two.woa/wa?id=000¶m=0'>click me</a>"; //original
NSString *body = @"This is a link: <a href='http://somewhere.com/two.woa/wa?id=000&param=0'>click me</a>"; //have also tried &
NSString *encodedBody =
[body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *formattedURL = [NSString stringWithFormat: @"mailto:myname@somedomain.com?subject=%@&body=%@", encodedSubject, encodedBody];
NSURL *url = [[NSURL alloc] initWithString:formattedURL];
[[UIApplication sharedApplication] openURL:url];
推荐答案
& href =http://www.blooberry.com/indexdot/html/topics/urlencoding.htm =nofollow noreferrer>网址编码标准
the ampersand would be %26 for HEX in URL Encoding standards
这篇关于如何编码“&”在HTML属性值的URL中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文