How to remove the letters (all non-numeric characters) from a string in PHP

2 Answers

0 votes
$s = '123php 998programming 89736129language';

$s =  preg_replace('/[^0-9]+/', '', $s);

echo $s;

 
/*
run:
  
12399889736129
   
*/

 



answered Jan 30, 2017 by avibootz
0 votes
$s = '-3.14php 998programming 89736129language';

$s =  preg_replace("/[^0-9,.-]/", "", $s);

echo $s;

 
/*
run:
  
-3.1499889736129
   
*/

 



answered Jan 30, 2017 by avibootz

Related questions

1 answer 165 views
2 answers 171 views
2 answers 268 views
2 answers 256 views
1 answer 207 views
...