public static function dissectURL(url:String) : Object
{
var keys : Array = ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"];
var hostExtractPattern:RegExp = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/;
var o : Object = hostExtractPattern.exec(url);
var r : Object = new Object();
for (var i:int = 0; i < keys.length; i++) { r[keys[i]] = o[i];Â Â Â }
return r;
}
An example of its use would be:
var protocol : String = dissectURL("http://www.mikecann.co.uk/?p=294").protocol;
trace(protocol);
It would trace "http".
Enjoy!
No comments:
Post a Comment