我需要一些函数来检查给定的值是否为url。如何检查给定的值是否是有效的URL
我有代码:
<?php
$string = get_from_db();
list($name, $url) = explode(": ", $string);
if (is_url($url)) {
$link = array('name' => $name, 'link' => $url);
} else {
$text = $string;
}
// Make some things
?>
看看这对你的作品:http://stackoverflow.com/questions/2390275/php-regex-for-validating-a -url – MacAnthony 2010-06-21 13:52:15
可能的重复:http://stackoverflow.com/questions/161738/what-is-the-best-regular-expression-to-check-if-a-string-is-a-valid-url – 2010-06-21 13:52:29
不是愚蠢 - 这两个人要求一个正则表达式,而这一个不是。 – nickf 2010-06-21 14:05:30