Template:Needs Translation/
函数名
|
Function: string llEscapeURL( string url );
|
参数:string url – A (preferably valid and unescaped URL) string.
|
返回值:返回一个字符串,该字符串是url的转义/编码版本,用“%20”等替换空格。该函数将把不属于[a-zA-Z0-9]的任何字符转义为“%xx”,其中“xx”是字符的十六进制值,以UTF-8字节形式表示。
|
注意事项
|
该函数不适合一次性转义url,因为协议之后的“:”以及所有分隔各个部分的“/”字符都将转义。相反,应该部分构建url;根据需要转义路径和查询字符串参数。
|
示例
|
示例1
string str = "http://wiki.secondlife.com/wiki/LSL Portal";
default
{
state_entry()
{
llOwnerSay("Plain string:\n\t" + str);
// output: "http://wiki.secondlife.com/wiki/LSL Portal"
llOwnerSay("Escaped string:\n\t" + llEscapeURL(str));
// output: "http%3A%2F%2Fwiki%2Esecondlife%2Ecom%2Fwiki%2FLSL%20Portal"
llOwnerSay("Escaped string unescaped again:\n\t" + llUnescapeURL( llEscapeURL(str) ));
// output: "http://wiki.secondlife.com/wiki/LSL Portal"
// because escaping and unescaping are exact opposite
// and unescaping an escaped string returns the original
// For readability's sake it would make more sense to do:
llOwnerSay("For readability's sake:\n\t" + "http://wiki.secondlife.com/wiki/" + llEscapeURL("LSL Portal"));
// output: "http://wiki.secondlife.com/wiki/LSL%20Portal"
}
}
|