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. Note also that the query part separator is "&" rather than "&" and so you will need to pass the output through htmlspecialchars to produce an XHTML-compliant URI.


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

Example 3

To produce an XHTML-compliant URI you need to pass the output through htmlspecialchars, like this:

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

See also