Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP preg replace only allow numbers

How can I modify this existing preg_replace to only allow numbers?

function __cleanData($c)  {     return preg_replace("/[^A-Za-z0-9]/", "",$c); } 
like image 758
Ryan Avatar asked Oct 07 '11 14:10

Ryan


1 Answers

I think you're saying you want to remove all non-numeric characters. If so, \D means "anything that isn't a digit":

preg_replace('/\D/', '', $c) 
like image 141
lonesomeday Avatar answered Sep 22 '22 23:09

lonesomeday