Skip to content

Instantly share code, notes, and snippets.

@moustaki
Created June 7, 2011 11:00
Show Gist options
  • Save moustaki/1012034 to your computer and use it in GitHub Desktop.
Save moustaki/1012034 to your computer and use it in GitHub Desktop.
Handle IRIs with Zend_Uri
/**
* Converts to a Zend_Uri object
* @protected
* @static
* @param string $s
* @return Zend_Uri
*/
protected static function uri($s)
{
if (!empty($s)) {
Zend_Uri::setConfig(array('allow_unwise' => true));
$ignore = Zend_Uri_Http::CHAR_ALNUM;
$ignore .= Zend_Uri_Http::CHAR_MARK;
$ignore .= Zend_Uri_Http::CHAR_RESERVED;
$ignore .= Zend_Uri_Http::CHAR_SEGMENT;
$s = preg_replace('{([^'. $ignore . '])}e', 'sprintf("%%%02X", ord("$1"))', $s);
return Zend_Uri::factory($s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment