<?php $s = "abc 123 and 4";$res = preg_replace('~\D+~', '', $s);echo $res;
Standard input is empty
1234
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!