gpt4 book ai didi

php - 分隔符不能是字母数字或反斜杠和 preg_match

转载 作者:IT老高 更新时间:2023-10-28 12:00:26 24 4
gpt4 key购买 nike

我有这个代码:

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

当我运行它返回这个错误:

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

最佳答案

您的模式需要一个分隔符。它应该像这样添加在模式的开头和结尾:

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

关于php - 分隔符不能是字母数字或反斜杠和 preg_match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7660545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com