使用Zend验证URL

3

我有一个URL字段,它可以是各种网站的URL。

是否有一个Zend框架验证类,可以像Zend_Validate_EmailAddress一样帮助我验证URL?

谢谢。


让我们看看Google说了什么... http://blog.motane.lu/2012/04/16/validate-urls-in-zend-framework/ - user1477388
同时,http://www.rondobley.com/2011/09/24/how-to-validate-a-url-with-a-scheme-and-hostname-in-zend-framework/ - user1477388
2个回答

8

似乎没有任何替代品了?有什么想法为什么以及要使用什么替代品? - Sgoettschkes
没关系,它仍然存在,只是由于某种原因在文档中缺失了! - Sgoettschkes

4

Adrian的回答是正确的,但如果像我一样懒惰,只想复制/粘贴

来自:http://framework.zend.com/manual/1.12/en/zend.uri.chapter.html

// Contains '|' symbol
// Normally, this would return false:
$valid = Zend_Uri::check('http://example.com/?q=this|that');

// However, you can allow "unwise" characters
Zend_Uri::setConfig(array('allow_unwise' => true));

// will return 'true'
$valid = Zend_Uri::check('http://example.com/?q=this|that');

// Reset the 'allow_unwise' value to the default FALSE
Zend_Uri::setConfig(array('allow_unwise' => false));

默认情况下,Zend_Uri将不接受以下字符:"{", "}", "|", "\", "^", "`"。这些字符被RFC定义为“不明智”和无效的;然而,许多实现确实接受这些字符作为有效的。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接