From Joomla! Documentation

Revision as of 04:36, 17 September 2008 by Chris Davenport (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Returns a string representation of the URI object. By default the full URI is string is returned, but which parts of the URI are to be returned can be customised with an argument. Note that if the URI is to be output to the user then it should be passed through the JRoute::_ static method first as this will ensure that it is SEF encoded.


string toString( $parts )


Argument Data type Description Default
$parts array Associative array of the parts of the URI that are to be rendered. If omitted, then the whole URI is rendered. array( 'scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment' )

The parts are as follows:

Name Description Set method
fragment Fragment. setFragment
host Host name or IP address. setHost
path Path. setPath
pass Password for authentication purposes. setPass
port Port number. setPort
query Query part, consisting of one or more query items. setQuery
scheme Scheme (protocol). setScheme
user User name for authentication purposes. setUser

Example 1

In this example, a URI object is output as a full URI string.

$uri = '';
$u =& JURI::getInstance( $uri );
echo 'URI is ' . $u->toString();

would output

URI is

Example 2

In this example, only the scheme, host and path are included.

$uri = '';
$u =& JURI::getInstance( $uri );
echo 'URI is ' . $u->toString( array( 'scheme', 'host', 'path' ) );

would output

URI is

See also