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
Post a Comment