Home  >  Article  >  Backend Development  >  php preg_match揭示警告

php preg_match揭示警告

WBOY
WBOYOriginal
2016-06-13 12:08:49940browse

php preg_match提示警告。
代码如下:

<?php<br />function isValidDomain($domain){<br />	if(preg_match("/^(http|ftp)://(www\.)?.+\.(com|org|net)$/i",$domain))<br />		return $domain.'是合法域名';<br />	else<br />		return $domain.'<b>不</b>是合法域名';<br />}<br /><br />echo isValidDomain("http://www.aixi.com");<br />?>



运行结果:
Warning: preg_match(): Unknown modifier '/' in D:\wamp\www\www.yoyou.com\this.php on line 3
http://www.aixi.com不是合法域名

ps:php是5.4版本
------解决思路----------------------
"/^(http
------解决思路----------------------
ftp):\/\/(www\.)?.+\.(com
------解决思路----------------------
org
------解决思路----------------------
net)$/i"

"#^(http
------解决思路----------------------
ftp)://(www\.)?.+\.(com
------解决思路----------------------
org
------解决思路----------------------
net)$#i"
------解决思路----------------------
对于斜杠   如果你不想转移   就用  # 或者 @  或者 ! 都行 
------解决思路----------------------
少了轉意義,所以出錯。

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