$ str = ' 12 | string ';
echo(int)$ str;
//output 12
If you like conventional solutions.
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
$ str = ' 12 | string ';
echo preg_replace('/(\d+)。 */',' \\ 1 ',$ str);