/**
* Javascript equivalent of PHP 'parse_url' function.
*/
function js_php_parse_url(url){
url = new String(url);
ret = new Array();
// Domain name and scheme
var regexp = new RegExp("([a-z0-9]+)\:\/\/([\.a-z0-9\-\_]+)", "i");
result = regexp.exec(url);
if(result){
ret.scheme = result[1];
ret.domain = result[2];
}
// Path
regexp.compile("[a-z]+\:\/\/[\.a-z0-9]+\/([a-z0-9\/\.\-\_]+)\/", "i");
result = regexp.exec(url);
if(result){
ret.path = result[1] + '/';
}
// file name
regexp.compile("[a-z]+\:\/\/[\.a-z0-9]+\/([a-z0-9\/\.\-\_]+)", "i");
result = regexp.exec(url);
if(result){
ret.filename = result[1];
}
else{
ret.filename = url;
}
// Ext.
temp = ret.filename.split('.');
ret.ext = temp[1];
// Port
regexp.compile("[a-z]+\:\/\/[\.a-z]+\:([0-9]+)", "i");
result = regexp.exec(url);
if(result){
ret.port = result[1];
}
// Query
temp = url.split('?');
if(temp[1]){
ret.query = temp[1];
}
return ret;
}
PHP and javascript snippets you can copy and paste.
Thursday, April 12, 2007
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2007
(71)
-
▼
April
(24)
- js_map_keyPress(actualKeyPress,keyPressToMatch,cal...
- js_get_keyCode(e)
- js_create_socialBookmarks(container,path_to_icons)
- js_ajax.js
- net_upload_photosToFlickr($yourFlickrEmailAddress,...
- js_is_image(ext)
- js_php_parse_url(url)
- file_do_download($fileName)
- xml_replace_nodeContent( &$node, &$new_content )
- arr_add_elementToStart($a,$el)
- fnc_call($funcName)
- sec_quote_SQLStr($sql)
- net_convert_arrayToUrlStr($arr)
- xml_get_nodeChildren($xpathObj,$path,$index=0)
- xml_get_XMLStrFromXPath($xpathObj,$path,$index=0)
- xml_remove_elementsByTagName($parentNode,$tagName)
- xml_append_childNode($parentNode,$childNode)
- xml_create_elementWithText($doc, $name, $value)
- xml_clone_xpathToNewDOM($origXPath,$path)
- xml_create_node($xml)
- xml_create_xpath($DOM)
- xml_create_DOM($xmlStr)
- xml_get_attribValue($node, $name, $default)
- xml_get_nodeSet($xpathObj,$path,$index=0)
-
▼
April
(24)
1 comment:
Tested 14 April 2007.
Post a Comment