如何修复Preg_match()警告?

时间:2014-01-23 13:16:56

标签: preg-match

我正在使用preg_match函数来完成我的程序

(preg_match('/^(f|ht)tps?\://', $this->sourceFilename))

但它显示了这样的警告

Warning: preg_match() [function.preg-match]: Unknown modifier '/'

如何修改?请帮帮我!!!

2 个答案:

答案 0 :(得分:0)

应该转义最后一个斜杠

答案 1 :(得分:0)

你需要逃避正则表达式中的/

preg_match('/^(f|ht)tps?:\//', $this->sourceFilename)

或使用不同的分隔符:

preg_match('#^(f|ht)tps?:/#', $this->sourceFilename)

顺便说一句,你不需要逃避: