PHP Preg_Match从字符串中提取逗号分隔值[重复]
问题描述:
Possible Duplicate:
PHP preg_match_all: Extract comma seperated list
I have a string that looks like: [something ="1,2,3"]
I need get everything between the quotes into a string. I'm sure that preg_match is the way to do this but i'm not sure of the expression to use.
$content = [something = "1,2,3"];
$new_string = preg_match('?regex?','$content');
可能重复: strong>
PHP preg_match_all:提取逗号分隔列表 p> blockquote >我有一个字符串,如下所示:
[something =“1,2,3”] code> 我需要将引号之间的所有内容都放到字符串中。 我确定preg_match是这样做的方法,但我不确定要使用的表达式。 p>
$ content = [something =“1,2,3 “]; $ new_string = preg_match('?regex?','$ content'); code> pre> div>
答
Try this:
$content = '[something = "1,2,3"]';
if (preg_match('/"([^"]+)"/', $content, $matches)) {
$matchedContent = $matches[1];
}