Public Method Details |
getPossibleDomains4url |
|
public array getPossibleDomains4url( string $url )
|
| |
Returns an array with all possible ways of writing that domain name.
example:www.blueshoes.org can be written as:http://www.blueshoes.orghttp://www.blueshoes.org/http://blueshoes.orghttp://blueshoes.org/http://111.111.111.111http://111.111.111.111/
|
| Parameter |
|
|
| Returns |
array |
|
parseUrlExtended |
|
public array parseUrlExtended( string $url )
|
| |
Parse a URL and return its components.
this method makes use of php's parse_url() and extends it.scheme://user:pass@host:port/path?query#fragmentexample: url https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#addressthe returned associative array contains these parts (if present):+-------------+-----------------------+---------------------------------------------------------+| PART | EXAMPLE | COMMENTS |+-------------+-----------------------+---------------------------------------------------------+| scheme | https | http https ftp (mailto) gopher news telnet || host | order.blue-shoes.com | || port | 81 | default is 80. used even if it's 80 (if it's there). || user | bill | || pass | gates | || path | /forms/form.php | starts with a slash || query | lang=fr&sid=456456 | the ? is missing but the &'s aren't || fragment | address | || + domain | blue-shoes.com | no dot after the top level domain (.com.) <= extended || + directory | /forms/ | starts and ends with a slash <= extended || + file | form.php | no slash at the beginning <= extended |+-------------+-----------------------+---------------------------------------------------------+
|
| Parameter |
|
|
| Returns |
array (see description) |
| Throws |
bool FALSE |
|
getUrlJunk |
|
public string getUrlJunk( string $junk, [ mixed $url ] )
|
| |
returns the desired parts of the given url as a string.
name definitions:even the W3C seems to have problems to name the parts of an url. what's an URL, URI, URN etc.so we came up with these names, partly from php, wherever the names came from, please use themas they are described here.scheme://user:pass@host:port/path?query#fragmentexample: url https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address[---]scheme [-------host-------] []port [------query-----] [-----]fragment[--]user [---domain---] [-----]directory[---]pass [-file-][-----path----][--absToFragment-------------------------------------------------------------------][--absToQuery--------------------------------------------------------------][--absToPath--------------------------------------------][--absToDirectory-------------------------------][--absToPort------------------------------][--relToFragment-------------------------][--relToQuery--------------------][--relToPath--][-----] relToDirectoryparam $junk:this works similar to php's date() function. you pass a string with letters.+----------------+--------+-------------------------+----------------------------------------------------------------------------------------+| PART | LETTER | EXAMPLE | RETURNED SEPARATOR CHARS |+----------------+--------+-------------------------+----------------------------------------------------------------------------------------+| schme | s | http | :// (if user, host or domain follows) || user | u | bill | -none- || pass | P | gates | : (if user was before) || host | h | order.blue-shoes.com | @ (if user or pass was before) || domain | d | blue-shoes.com | -none- || port | o | 81 | : (if host or domain was before) || port | O (oh) | 81 | same as 'o' but only returned if != 80 (default port for http) || path | p | /forms/form.php | -none- || directory | i | /forms/ | -none- || file | f | form.php | -none- || query | q | lang=fr&sid=456456 | ? (if host, domain, port, path, directory, file or 3,4,5,8, or 9 was before) || fragment | F | address | # (if host, domain, port, path, directory, file, query or 2,3,4,5,7,8 or 9 was before) || absToFragment | 1 | https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address || absToQuery | 2 | https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456 || absToPath | 3 | https://bill:gates@order.blue-shoes.com:81/forms/form.php || absToDirectory | 4 | https://bill:gates@order.blue-shoes.com:81/forms/ || absToPort | 5 | https://bill:gates@order.blue-shoes.com:81 || relToFragment | 6 | /forms/form.php?lang=fr&sid=456456#address || relToQuery | 7 | /forms/form.php?lang=fr&sid=456456 || relToPath | 8 | /forms/form.php || relToDirectory | 9 | /forms/ |+----------------+--------+-------------------------+----------------------------------------------------------------------------------------+note I: the parts are returned including "separator chars" even though the parts above are describedto be without them. eg if you want the port, you don't get '81' you get ':81' here. if youare not happy with that, use $this->parseUrlExtended() and smile.note II: if a browser requests a website using a #fragment part, the fragment won't be submittedalong with the address to the server. this information will be kept by the client browserto jump to the right place once the page has been rendered.examples:getUrlJunk('suPhopqF', 'https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address');returns 'https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address'getUrlJunk('1', 'https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address');returns 'https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address'getUrlJunk('suPhopqF', 'https://order.blue-shoes.com/forms/form.php');returns 'https://order.blue-shoes.com/forms/form.php'maybe also check the ecg tests.
|
| Parameter |
|
|
|
| mixed |
$url |
= >>NULL<< |
|
(an url as a string, a hash that you got from $this->parseUrlExtended(), null if you want to use the current user-requested url.) |
|
| Returns |
string |
| Throws |
bool FALSE |
|
glueUrl |
|
public string glueUrl( array $url )
|
| |
opposite function of php's parse_url() and $this->parseUrlExtended().
|
| Parameter |
|
|
| Returns |
string the glued url
@throw bool FALSE |
|
getDomain4url |
|
public string getDomain4url( string $url, [ integer $num ] )
|
| |
Return the domain part of an url.
example:$url = 'http://some.really.long.domain.com/dir/file.html';$topLevelDomain = getDomain($url, 1); // 'com'$secondLevelDomain = getDomain($url, 2); // 'domain.com'$thirdLevelDomain = getDomain($url, 3); // 'long.domain.com'$fullDomain = getDomain($url, -1); // 'some.really.long.domain.com'
|
| Parameter |
|
|
|
| integer |
$num |
= >>2<< |
|
number of domains (parts) to return. default is 2. |
|
| Returns |
string the domain
@throw bool FALSE |
|
getDirectory4url |
|
public string getDirectory4url( string $url )
|
| |
Return the directory part of an url.
examples:'http://blue-shoes.com:81/forms/form.php?lang=fr' => '/forms/''http://blue-shoes.com:81/forms/' => '/forms/''http://blue-shoes.com:81/file.html' => '/''http://blue-shoes.com:81/unknown' => '/' <= 'unknown' may be a directory... but we have to treat it as a file.'http://blue-shoes.com/' => '/''http://blue-shoes.com' => '/' <= special case.
|
| Parameter |
|
|
| Returns |
string the directory
@throw bool FALSE |
|
getFile4url |
|
public string getFile4url( string $url )
|
| |
Return the file part of an url.
examples:'http://blue-shoes.com:81/forms/form.php?lang=fr' => 'form.php''http://blue-shoes.com:81/forms/' => '''http://blue-shoes.com:81/file.html' => 'file.html''http://blue-shoes.com:81/unknown' => 'unknown' <= 'unknown' may be a directory... but we have to treat it as a file.'http://blue-shoes.com/' => '''http://blue-shoes.com' => ''
|
| Parameter |
|
|
| Returns |
string the file
@throw bool FALSE |
|
enableUrl |
|
public string enableUrl( string $str )
|
| |
Makes the urls and emails in a string clickable.
Example:$string = "I was a little yellow@duck.com who had a homepage at <http://me.duck.com>,http://www.me.duck.com or www.duck.com with ftp://file.duck.com. I'm a developer in Norway(www.norge.no), andworks for DB Medialab, http://db.no, aka (www.db.no) [www.db.no], <www.duck.com> or {www.duck.com}. We are developing these sites http://www.dagbladet.no/nyheter/,http://www.dagbladet.no/nyheter/2001/01/29/239330.html, and http://start.no.";echo $enabled_urls_string = enableUrl($string);will print out:I was a little <a href="mailto:yellow@duck.com">yellow@duck.com</a> who had a homepage at <<a href="http://me.duck.com" target="_blank">http://me.duck.com</a>>,<a href="http://www.me.duck.com" target="_blank">http://www.me.duck.com</a> or <a href="http://www.duck.com" target="_blank">www.duck.com</a> with <a href="ftp://file.duck.com." target="_blank">ftp://file.duck.com.</a> I'm a developer in Norway(<a href="http://www.norge.no" target="_blank">www.norge.no</a>), andworks for DB Medialab, <a href="http://db.no" target="_blank">http://db.no</a>, aka (<a href="http://www.db.no" target="_blank">www.db.no</a>) [<a href="http://www.db.no" target="_blank">www.db.no</a>], <www.duck.com> or {www.duck.com}. We are developing these sites <a href="http://www.dagbladet.no/nyheter/" target="_blank">http://www.dagbladet.no/nyheter/</a>,<a href="http://www.dagbladet.no/nyheter/2001/01/29/239330.html" target="_blank">http://www.dagbladet.no/nyheter/2001/01/29/239330.html</a>, and <a href="http://start.no." target="_blank">http://start.no.</a>CAUTION: as you can see in the example above, a few things don't work (properly):- if a url is at the end of a sentence (which ends with a dot) that dot is added to the url.there are cases where it doesn't matter, but -> fix it.- <www.duck.com> is not url-enabled- {www.duck.com} is not url-enabledWritten by Fredrik Kristiansen (russlndr at online.no) and Albrecht Guenther (ag at phprojekt.de).
|
| Parameter |
|
|
| Returns |
string |
|
hashArrayToQueryString |
|
public string hashArrayToQueryString( array &$hashArray, [ string $prefix, string $firstSeparator ] )
|
| |
Takes a hash array and returns a query string.
in other words make arrays persistant for clickthroughs.this function is rated INTELLIGENT :)example I:$hash['in']['a']['color'] = 'green';$hash['in']['a']['message'] = 'hello world';echo hashArrayToQueryString($hash) prints out "&in[a][color]=green&in[a][message]=hello+world"example II:$hash['in']['a']['color'] = 'green';$hash['in']['a']['message'] = 'hello world';echo hashArrayToQueryString($hash, 'aPoorMansNamespace', '?')prints out '?aPoorMansNamespace[in][a][color]=green&aPoorMansNamespace[in][a][message]=hello+world'if you pass a zerobased array that'll work also:$arr = array('foo', 'bar') => '&0=foo&1=bar'it starts with a "&" and not a "?" because there might be other params already set for your url.if not, you can trick it by doing someting like domain.com/myfile.php?dummy=&yourParamsHerehave no fear, even ubs.com/e-banking uses a querystring var called dummy :) (or change the 3rd param).
|
| Parameter |
|
| array |
&$hashArray |
|
|
hashArray of the values |
|
|
| string |
$prefix |
= >>''<< |
|
see example |
|
|
| string |
$firstSeparator |
= >>'&'<< |
|
default is '&' may also be '?' or ''. |
|
| Returns |
string returns a string that can be attached to the querystring. returns an empty string '' if param $hashArray is not an array. |
|
addQueryParam |
|
public void addQueryParam( string $url )
|
| |
Adds a key/value pair to the querystring of the given url.
Caution: If you are not sure or if it's possible that the param already exists in the url,better use modifyQueryParam(). this method just adds it, doesn't check for existance.note: param $val is urlEncoded, so don't do it yourself.example: addQueryParam('http://www.domain.com/file.php?key=val', 'key2', 'val2');don't try this at home! you cannot just add &key=val to the url. because your url mightlook like http://www.domain.com/file.php?x=y#anchor, go figure.
|
| Parameter |
|
|
| Returns |
void |
|
modifyQueryParam |
|
public void modifyQueryParam( string $url, string $key, string $val, [ string $force ] )
|
| |
Changes the value of a querystring param in an url.
note I: param $key is case sensitive.note II: param $val is urlEncoded, so don't do it yourself.example: modifyQueryParam('http://www.domain.com/file.php?key=val', 'key', 'newval');
|
| Parameter |
|
|
|
|
|
|
|
| string |
$force |
= >>TRUE<< |
|
if the key does not exist in the url, should it be added? default=TRUE.
@throw bool FALSE if $url is not a valid url. |
|
| Returns |
void |
|
crossUrlDecode |
|
public string crossUrlDecode( $source )
|
| |
cross (browser/configuration/encoding) url decode.
note: %A and %D (\r\n) need to be written as %A[somechar],example %Ax %Dx because this functions expects (and removes)another char, just like in %20 for a space.if you're gonna correct this, please correct it in the codeaswell which uses this method, namely Bs_TextType. --andrejgot this from:igjav@cesga.es 16-May-2002 05:48http://www.php.net/manual/en/function.urldecode.phpThis seems to decode correctly between most browsers and charater codingconfigurations. Specially indicated for direct parsing of URL as it comes onenvironment variables
|
| Parameter |
|
|
$source |
|
|
Warning: documentation is missing. |
|
| Returns |
string |
|
getLastDir |
|
public mixed getLastDir( string $url )
|
| |
returns the last dir of an url.
i'm not that proud of that code :/examples for last dir:/some/path/file/ => 'file'/some/path/something => array('path', 'file) not sure if something is a file or a dir./some/path/something.html => 'path'
|
| Parameter |
|
| string |
$url |
|
|
(without the http://www.domain.com part) |
|
| Returns |
mixed a string or a vector with 2 strings |
| Throws |
false |
|
Bs_Url |
|
public void Bs_Url( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|