PHP validation/regex for URL

后端 未结 21 2471
青春惊慌失措
青春惊慌失措 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 01:59

    For anyone developing with WordPress, just use

    esc_url_raw($url) === $url
    

    to validate a URL (here's WordPress' documentation on esc_url_raw). It handles URLs much better than filter_var($url, FILTER_VALIDATE_URL) because it is unicode and XSS-safe. (Here is a good article mentioning all the problems with filter_var).

提交回复
热议问题