Reputation: 487
$thisdate = '2011-01-18 14:52:33';
$security = preg_replace('/[^\d\s]/', '', $thisdate);
echo $security;
This results in 20110118 145233
How would i get rid of the space?
Thanks.
Upvotes: 0
Views: 65
Reputation: 7853
While changing the regex is definitely the superior answer...
str_replace
can also work.
$security = str_replace($security, '\s', '');
Upvotes: 0
Reputation: 32148
your regex matches everything that is not(^
) digit(\d
) or space(\s
)
so if you remove the \s
preg_replace('/[^\d]/', '', $thisdate);
will replace everything except digits
Upvotes: 3