PARSE_URL
Syntax | Return Value | Arguments | Keywords | Examples | Version History | See Also
The PARSE_URL function breaks a URL string into substrings that correspond to the URL_* properties of IDLnet* objects.
Note
This is not an object method and does not set any object properties.
Note
If a port number is not found in the URL string parameter, the default port value is 80.
PARSE_URL is a pure string-processing routine. Validation of the values is left to the user. The returned value is a structure created by applying the following rules to the input URL string:
|
URL Index
|
URL Section
|
Example
|
Rule
|
|
0
|
Scheme
|
"http", "https", or "ftp"
|
From beginning of URL string up to (but not including) "://"
|
|
1
|
Username
|
anonymous
|
If `@' is present before the first single `/', everything from "://" to either `:' or `@' if `:' is not present
|
|
2
|
Password
|
make-something-up
|
If both `@' and `:' are present before the first single `/', everything from `:' to `@'
|
|
3
|
Host
|
somehost.com
|
Everything from "://" or `@' to `:' or first single `/'
|
|
4
|
Port
|
80
|
If `:' follows the host name, everything between `:' and the first single `/'
|
|
5
|
Path
|
|
Everything between the first single `/' and `?' or end of string
|
|
6
|
Query
|
|
Everything from `?' to the end of the string
|
URL string components are illustrated in the following example:
This routine is written in the IDL language. Its source code can be found in the file parse_url.pro in the lib subdirectory of the IDL distribution.
Syntax
Result = PARSE_URL(URL)
Return Value
PARSE_URL returns an anonymous structure containing the disassembled segments of the URL. The fields in the structure are:
All fields contain string values.
To see the structure tag names, enter the following code in the IDL command line:
Arguments
URL
A URL in string form.
Keywords
None.
Examples
The following example strips a known URL to its component strings.
; Start with a hypothetical URL string
urlString = 'http://someserver.com/path/to/firstfile.dat'
PRINT, 'Original URL string = '+urlString
; Split the URL into its component substrings
urlComponents = PARSE_URL(urlString)
; Populate an IDLnetURL object with the URL information
urlObj =OBJ_NEW('IDLnetURL')
urlObj->SetProperty, URL_SCHEME = urlComponents.scheme, $
URL_HOST = urlComponents.host, $
URL_PATH = urlComponents.path
; Get the object's URL property values, and print them
urlObj->GetProperty, URL_SCHEME = urlScheme
urlObj->GetProperty, URL_HOST = urlHost
urlObj->GetProperty, URL_PATH = urlPath
PRINT, 'URL scheme = '+urlScheme
PRINT, 'URL host = '+ urlHost
PRINT, 'URL path = '+urlPath
Version History
See Also
IDLnetURL