PHP Preg_Match从字符串中提取逗号分隔的值
可能重复:PHP Preg_Match从字符串中提取逗号分隔的值,php,regex,string,Php,Regex,String,可能重复: 我有一个字符串,看起来像:[something=“1,2,3”] 我需要把引号之间的所有内容都转换成字符串。我确信preg_match是实现这一点的方法,但我不确定要使用的表达式 $content = [something = "1,2,3"]; $new_string = preg_match('?regex?','$content'); 试试这个: $content = '[something = "1,2,3"]'; if (preg_match('/"([^"]+)"/
我有一个字符串,看起来像:
[something=“1,2,3”]
我需要把引号之间的所有内容都转换成字符串。我确信preg_match是实现这一点的方法,但我不确定要使用的表达式
$content = [something = "1,2,3"];
$new_string = preg_match('?regex?','$content');
试试这个:
$content = '[something = "1,2,3"]';
if (preg_match('/"([^"]+)"/', $content, $matches)) {
$matchedContent = $matches[1];
}
非常感谢你的快速回答。很好!