I have a string like this:
SELECT NOW(),DATE_ADD(NOW(), INTERVAL -11 day)
and I need to get the number which can be positive or negative.
I tried using:
preg_replace("/^-?[0-9]/", '', $str);
but it doesn’t seem to work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to “extract” the number from the string, and not manipulate it then
preg_match()is what you should be using. If you want to remove numbers from a string then just remove the^from your regex which is restricting your regex to match the beginning of the string.Regex:
preg_match syntax: