分隔符不得为字母数字或反斜杠以及preg_match [英] Delimiter must not be alphanumeric or backslash and preg_match

查看:88
本文介绍了分隔符不得为字母数字或反斜杠以及preg_match的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

$string1 = "My name is 'Kate' and im fine"; 
$pattern = "My name is '(.*)' and im fine"; 
preg_match($pattern , $string1, $matches);
echo $matches[1];

,当我运行时,它将返回此错误:

and when im run it returns this error:

警告:preg_match()[function.preg-match]:分隔符不能为字母数字或反斜杠

Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash

推荐答案

您需要为模式使用定界符.应该将其添加到模式的开头和结尾,如下所示:

You need a delimiter for your pattern. It should be added at the start and end of the pattern like so:

$pattern = "/My name is '(.*)' and im fine/";  // With / as a delimeter 

这篇关于分隔符不得为字母数字或反斜杠以及preg_match的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆