PHP validation/regex for URL

后端 未结 21 2055
青春惊慌失措
青春惊慌失措 2020-11-22 01:19

I\'ve been looking for a simple regex for URLs, does anybody have one handy that works well? I didn\'t find one with the zend framework validation classes and have seen sev

21条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 02:00

    As per the PHP manual - parse_url should not be used to validate a URL.

    Unfortunately, it seems that filter_var('example.com', FILTER_VALIDATE_URL) does not perform any better.

    Both parse_url() and filter_var() will pass malformed URLs such as http://...

    Therefore in this case - regex is the better method.

提交回复
热议问题