Copy code The code is as follows:
if (!preg_match("/^(http|ftp):/", $_POST[' url'])) {
$_POST['url'] = 'http://'.$_POST['url'];
}
This code first uses regular expressions The expression checks whether there is "http" or "ftp" and a colon ":" in the string. If not, add "http://" in front of the string.
http://www.bkjia.com/PHPjc/321864.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321864.htmlTechArticleCopy the code as follows: if (!preg_match("/^(http|ftp):/", $_POST ['url'])) { $_POST['url'] = 'http://'.$_POST['url']; } This code first uses a regular expression to check whether there is "...