Replace curly braced expression with one item from the expression
问题 Here is a sample string: {three / fifteen / one hundred} this is the first random number, and this is the second, {two / four} From the brackets, I need to return a random value for example: One hundred is the first random number, and this is the second, two My code: function RandElement($str) { preg_match_all('/{([^}]+)}/', $str, $matches); return print_r($matches[0]); } $str = "{three/fifteen/one hundred} this is the first random number, and this is the second, {two/four}"; RandElement($str