php - 如何从字符串中获取特定值

php - how to get specific value from the string

我在尝试从字符串中提取特定值但未获得正确输出时遇到问题。

$string = com.xyz.ghop.service.sprint.Sprint@1b0258c[id=257,rapidViewId=94,state=CLOSED,name=Alert Success 5,goal=,startDate=2016-08-16T20:20:46.730+05:30,endDate=2016-08-26T20:20:00.000+05:30,completeDate=2016-08-26T21:18:53.928+05:30,sequence=257]

我想要 name= 中的值直到逗号,我尝试使用 preg_match_all 但它只给出了第一个词。

这是我试过的:

preg_match_all("/(?=name\=([^\W]+))/", $string, $matches); 
$resulte = implode(",", $matches[1]); 

请帮忙

谢谢

有多种方法,可用于 preg_match 或 preg_match_all

$results = preg_match('#name=(.*?),#', $matches);

$results = preg_match('#name=([^,]+),#', $matches);

您可以尝试类似的方法:

preg_match("/name=(.+?),/", $string, $matches);
$result = end($matches);

希望对您有所帮助!