Dython
Dython

Reputation: 134

php - how to get specific value from the string

I am facing issue when trying to extract specific value from the string but not getting the proper output.

$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]

I want the value inside name= till the comma and I tried with preg_match_all but it just gives the first word.

This is what I tried:

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

Please help

Thanks

Upvotes: 3

Views: 991

Answers (2)

hassan
hassan

Reputation: 8288

there are multiple approaches , available on whether preg_match or preg_match_all

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

OR

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

Upvotes: 5

Rwd
Rwd

Reputation: 35170

You could try something like:

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

Hope this helps!

Upvotes: 5

Related Questions