Home  >  Article  >  Backend Development  >  PHP为表单获取的URL 地址预设 http 字符串函数代码_php技巧

PHP为表单获取的URL 地址预设 http 字符串函数代码_php技巧

WBOY
WBOYOriginal
2016-05-17 09:25:10838browse
复制代码 代码如下:

if (!preg_match("/^(http|ftp):/", $_POST['url'])) {
$_POST['url'] = 'http://'.$_POST['url'];
}

该代码先用正则表达式检查字符串中是否有"http”或"ftp"和冒号":",如果没有,在字符串前添加"http://"
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn