php - Get value after particular character in string -


i have string follows

$str = 'asdasdasd,sdfsdfsdf mynumber=1234, 2323 dfdfdf9898 sdfsdfdsf 234'; 

i'd return digits within mynumber=1234.

desired outcome

$str = '1234'; 

i use following regex preg_replace('/\mynumber=\d+/', '', $y) replace when required, works perfectly, i'm not sure how use extract numbers after = sign mynumber=1234?

you can use preg_match following regex:

\bmynumber=(\d+) 

see regex demo

the value available in group 1. (\d+) matches , captures 1+ digits group part of resulting array.

demo:

$re = '~\bmynumber=(\d+)~';  $str = "asdasdasd,sdfsdfsdf mynumber=1234, 2323 dfdfdf9898 sdfsdfdsf 234";  preg_match($re, $str, $m); echo $m[1]; 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -