分隔符不能是字母数字或反斜杠和 preg_match [英] Delimiter must not be alphanumeric or backslash and preg_match

查看:28
本文介绍了分隔符不能是字母数字或反斜杠和 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天全站免登陆