Link | url_normalize |
Author | Jason Huck |
Category | String |
Version | 8.5.x |
License | Public Domain |
Posted | 22 Sep 2008 |
Updated | 22 Sep 2008 |
More by this author... |
This tag can be used to convert a relative URL into an absolute one. Accepts two parameters: a base URL to compare against (representing the path to the file that calls the relative URL), and a relative URL to convert.
url_normalize( -url='../../../foo.jpg', -base='/path/to/thing/that/calls/foo/' ); -> '/path/to/thing/foo.jpg'
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define_tag( 'normalize', -namespace='url_', -req='url', -copy, -req='base', -copy, -priority='replace', -encodenone, -description='Given a base URL, converts the given relative URL to absolute.' ); // URLs beginning with / or http do not need to be converted (#url->beginswith('http://') || #url->beginswith('/')) ? return(#url); !#base->endswith('/') ? #base->append('/'); if(#url->beginswith('../')); // count the number of paths to remove local('dirsToRemove') = #url->split('../')->size - 1; #base->removetrailing('/'); loop(#dirsToRemove); #base->removetrailing('/' + #base->split('/')->last); #url->removeleading('../'); /loop; #base->append('/'); return(#base + #url); else(#url == '.'); return(#base); else(#url->beginswith('./')); return(#base + #url->removeleading('./')&); else; return(#base + #url); /if; /define_tag;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft