Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 910
Dython Avatar asked May 08 '26 00:05

Dython


2 Answers

there are multiple approaches , available on whether preg_match or preg_match_all

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

OR

$results = preg_match('#name=([^,]+),#', $matches);
like image 108
hassan Avatar answered May 09 '26 15:05

hassan


You could try something like:

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

Hope this helps!

like image 26
Rwd Avatar answered May 09 '26 15:05

Rwd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!