如何在PHP中减去字符串中的数字?

There is a string variable containing number data , say $x = "OP/12/DIR"; . The position of the number data may change at any circumstance by user desire by modifying it inside the application , and the slash bar may be changed by any other character ; but the number data is mandatory. So how to extract the number data from the string ?

Replace everything that is NOT a number with an empty string.

  $numbers = preg_replace('/[^0-9]*/','',$x);

Replace everithing that is not a number:

  $numbers = preg_replace( '/[^\d\.]/', '', $input ); 

or if you will have decimal:

$numbers = preg_replace ( '#\D*?(\d+(\.\d+)?)\D*#', '$1', $input );