0
$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.

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

take the \s out of the regex

Comments

0

While changing the regex is definitely the superior answer...

str_replace can also work.

$security = str_replace($security, '\s', '');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.