__construct(string $url) : object
string
objectaddQuery(array $query) : object
eg...
$url = new URLParser\URL('http://www.example.com'); $url->addQuery(array( 'val1' => 'stuff', 'val2' => 'more stuff', )); echo $url->make();
Outputs...
http://www.example.com?val1=stuff&val2=more+stuff
array
objectanchor(string $anchor) : mixed
eg...
$url = new URLParser\URL('http://www.example.com'); $url->anchor('products'); echo $url->make();
Outputs...
http://www.example.com/#products
string
mixedappendSegment(string $newSegment, string $appendAfter) : object
Optionally a segment can be specified ($appendAfter) and the new segment will be inserted immediately following the instance of $appendAfter.
eg...
$url = new URLParser\URL('http://www.example.com/products/services'); $url->appendSegment('test'); echo $url->make() . "<br/>"; $url->appendSegment('argh','products'); echo $url->make() . "<br/>";
Outputs...
http://www.example.com/products/services/test
http://www.example.com/products/argh/services/test
string
string
objecthost(string $host) : mixed
eg...
$url = new URLParser\URL('http://www.example.com/stuff?val1=foo'); $url->host('www.google.ca'); echo $url->make();
Outputs...
http://www.google.ca/stuff?val1=foo
string
mixedmake()
pass(string $pass) : mixed
User must be specified first.
eg...
$url = new URLParser\URL('http://www.example.com/stuff?val1=foo'); $url->user('joe'); $url->pass('foobar'); echo $url->make();
Outputs...
http://joe:foobar@www.example.com/stuff?val1=foo
string
mixedport(string $port) : mixed
eg...
$url = new URLParser\URL('http://www.example.com/stuff?val1=foo'); $url->port(8080); echo $url->make();
Outputs...
http://www.example.com:8080/stuff?val1=foo
string
mixedprependSegment(string $newSegment, string $prependBefore) : object
Optionally a segment can be specified ($prependBefore) and the new segment will be inserted immediately before the instance of $prependBefore.
eg...
$url = new URLParser\URL('http://www.example.com/products/services'); $url->prependSegment('test'); echo $url->make() . "<br/>"; $url->prependSegment('argh','products'); echo $url->make() . "<br/>";
Outputs...
http://www.example.com/test/products/services
http://www.example.com/test/argh/products/services
string
string
objectprotocol(string $protocol) : mixed
eg...
$url = new URLParser\URL('http://www.example.com'); $url->protocol('ftp'); echo $url->make();
Outputs...
ftp://www.example.com
string
mixedquery(string $query) : string
eg...
$url = new URLParser\URL('http://www.example.com?val1=products&val2=services'); echo $url->query('val1') . "<br/>"; echo $url->query('val2') . "<br/>"; echo $url->query('val3') . "<br/>"; // Returns FALSE echo $url->query() . "<br/>";
Outputs...
products
services
val1=products&val2=services
string
stringqueryArray() : array
eg...
$url = new URLParser\URL('http://www.example.com?val1=products&val2=services'); var_dump($url->queryArray());
Outputs...
array(2) { ["val1"]=> string(8) "products" ["val2"]=> string(8) "services" }
arraysegmentArray() : array
eg...
$url = new URLParser\URL('http://www.example.com/products/services'); var_dump($url->segmentArray());
Outputs...
array(2) { [0]=> string(8) "products" [1]=> string(8) "services" }
arraysegments(string $search) : mixed
eg...
$url = new URLParser\URL('http://www.example.com/products/services'); echo $url->segments('products') . "<br/>"; echo $url->segments('services') . "<br/>"; echo $url->segments('abcd') . "<br/>"; // Returns FALSE echo $url->segments() . "<br/>";
Outputs...
(true)
(true)
(false)
/products/services
string
mixedstripQueries() : object
eg...
$url = new URLParser\URL('http://www.example.com?val1=products&val2=services'); $url->stripQueries(); echo $url->make();
Outputs...
http://www.example.com
objectstripQuery(string $query) : object
eg...
$url = new URLParser\URL('http://www.example.com?val1=products&val2=services'); $url->stripQuery('val1'); echo $url->make();
Outputs...
http://www.example.com?val2=services
string
objectstripSegment(string $s) : object
eg...
$url = new URLParser\URL('http://www.example.com/products/services'); $url->stripSegment('products'); echo $url->make();
Outputs...
http://www.example.com/services
string
objectstripSegments() : object
eg...
$url = new URLParser\URL('http://www.example.com/products/services?val1=stuff&val2=more+stuff'); $url->stripSegments(); echo $url->make();
Outputs...
http://www.example.com?val1=stuff&val2=more+stuff
objectswapQueries($queries) : object
eg...
$url = new URLParser\URL('http://www.example.com?val1=products&val2=services'); $url->swapQueries(array( 'val1' => 'valX', 'val2' => 'valY', )); echo $url->make();
Outputs...
http://www.example.com?valX=products&valY=services
objectswapQuery($oldName, $newName) : object
eg...
$url = new URLParser\URL('http://www.example.com?val1=products&val2=services'); $url->swapQuery('val1','valX'); echo $url->make();
Outputs...
http://www.example.com?val2=services&valX=products
objectswapSegments(array $newSegments) : object
eg...
$url = new URLParser\URL('http://www.example.com/oldSegment/home'); $url->swapSegments(array( 'oldSegment' => 'newSegment', 'home' => 'main', )); echo $url->make();
Outputs...
http://www.example.com/newSegment/main
array
objectto(string $url) : object
This is useful for scenarios where you wish to batch add query strings to multiple URLs. You can setup the queries on one object and then to() and make() multiple calls to generate new URLs.
string
objectuser(string $user) : mixed
eg...
$url = new URLParser\URL('http://www.example.com/stuff?val1=foo'); $url->user('joe'); echo $url->make();
Outputs...
http://joe@www.example.com/stuff?val1=foo
string
mixedcurrentURL() : string
Used by the __construct method.
stringinsertIntoArrayAtKey($array, $key, $newKeyValuePairs, $offset)
renameArrayKey(array $array, string $oldKey, string $newKey) : array
eg...
$arr = array( 'foo' => 'bar', 'foo2' => 'bar2', );
$arr = $this->renameArrayKey( $arr, 'foo', 'test' );
returns...
array( 'test' => 'bar', 'foo2' => 'bar2', )
array
string
string
arrayrenameArrayKeys(array $array, array $newKeys) : array
eg...
$arr = array( 'foo' => 'bar', 'foo2' => 'bar2', );
$arr = $this->renameArrayKey( $arr, array( 'foo' => 'test' ) );
returns...
array( 'test' => 'bar', 'foo2' => 'bar2', )
array
array
arraysliceArrayAtKey(array $array, string $key, boolean $offset) : array
Optionally specify "$offset" to indicate that the slice should occur AFTER $offset keys, meaning the function will return...
In the case that $key does not exist or is not specified the function will still return 2 arrays. If $offset is not specified or is less than 0 (prepend mode), the returned array at index 0 will contain a blank array and index 1 will contain all of the elements from the original array. If $offset is specified and is greater than 0 (append mode) index 0 will contain all of the elements from the original array and index 1 will contain a blank array.
Example 1:
$arr = array( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3', 'key4' => 'val4', 'key5' => 'val5', );
Note: $offset not specificed (0) means the function operates in "prepend" mode
$arr = $this->sliceArrayAtKey( $arr, 'key2' );
returns....
array( [0] => array( 'key1' => 'val1', ), [1] => array( 'key2' => 'val2', 'key3' => 'val3', 'key4' => 'val4', 'key5' => 'val5', ), )
Example 2:
$arr = array( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3', 'key4' => 'val4', 'key5' => 'val5', );
Note: $offset > 0 (1) means the function operates in "append" mode
$arr = $this->sliceArrayAtKey( $arr, 'key2', 1 );
returns....
array( [0] => array( 'key1' => 'val1', 'key2' => 'val2', ), [1] => array( 'key3' => 'val3', 'key4' => 'val4', 'key5' => 'val5', ), )
Example 3:
$arr = array( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3', 'key4' => 'val4', 'key5' => 'val5', );
$arr = $this->sliceArrayAtKey( $arr, 'key2', 3 );
returns....
array( [0] => array( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3', 'key4' => 'val4', ), [1] => array( 'key5' => 'val5', ), )
Example 4:
$arr = array( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3', 'key4' => 'val4', 'key5' => 'val5', );
$arr = $this->sliceArrayAtKey( $arr, 'key2', -1 );
returns....
array( [0] => array( ), [1] 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3', 'key3' => 'val4', 'key5' => 'val5', ), )
Example 5:
Note: $offset is not specified and the function defaults to "prepend" mode, $key does not exist.
$arr = array( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3', 'key4' => 'val4', 'key5' => 'val5', );
$arr = $this->sliceArrayAtKey( $arr, 'key6' );
returns.... array( [0] => array( ), [1] 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3', 'key3' => 'val4', 'key5' => 'val5', ), )
Example 6:
Note: $offset is 1 and the function defaults to "append" mode, $key does not exist
$arr = array( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3', 'key4' => 'val4', 'key5' => 'val5', );
$arr = $this->sliceArrayAtKey( $arr, 'key6', 1 );
returns.... array( [0] => array( 'key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3', 'key3' => 'val4', 'key5' => 'val5', ), [1] ), )
array
string
boolean
array$resetURL : array
$url : array
This is the property which is actively used and modified throughout the functions of this class.