public function testBuildURL() { //PU_BuildURL($target = null, $includeInGet = null, $excludeFromGet = null, $glue = '&') $this->assertEquals('http://TEST/test.php', PU_BuildURL()); $this->assertEquals('http://TEST/target.php', PU_BuildURL('/target.php')); $this->assertEquals('target.php', PU_BuildURL('target.php')); $this->assertEquals('target.php?a=z', PU_BuildURL('target.php', array('a' => 'z'))); $this->assertEquals('target.php?a=1&b=2', PU_BuildURL('target.php?a=1&b=2')); $this->assertEquals('target.php?a=z&b=2', PU_BuildURL('target.php?a=1&b=2', array('a' => 'z'))); $this->assertEquals('target.php?a=z&b=2&c=y', PU_BuildURL('target.php?a=1&b=2', array('a' => 'z', 'c' => 'y'))); $this->assertEquals('target.php?a=1&b=2&c=y', PU_BuildURL('target.php?a=1&b=2', array('c' => 'y'))); $this->assertEquals('target.php', PU_BuildURL('target.php', null, array('a'))); $this->assertEquals('target.php?b=2', PU_BuildURL('target.php?a=1&b=2', null, array('a'))); $this->assertEquals('target.php?b=2', PU_BuildURL('target.php?a=1&b=2', array('a' => 'z'), array('a'))); $this->assertEquals('target.php?b=2&c=y', PU_BuildURL('target.php?b=2', array('a' => 'z', 'c' => 'y'), array('a'))); $this->assertEquals('target.php?c=y', PU_BuildURL('target.php?c=z', array('c' => 'y'), array('a'))); }
/** * Build a html link (A+HREF html tag) with label and url and GET parameters * * @version 1.0.1 * @date 20091203: added $attrs parameter * @param $label string: the text of the link * @param $includeInGet (optional) array of pairs: parameters to add as GET in the url * @param $excludeFromGet (optional) array of strings: parameters to remove from GET in the url * @param $target (optional) string: the target script url (current script if missing) * @return string the complete html link * * TODO: support attrs!!! */ function PU_BuildHREF($label, $includeInGet = null, $excludeFromGet = null, $target = null, array $attrs = null) { $url = PU_BuildURL($target, $includeInGet, $excludeFromGet); $href = '<a href="' . $url . '">' . $label . '</a>'; return $href; }