I have a string like “My String 2” and I like to get only num value “2”.
I try to do that you see below but result is egal to 0.
$AlphaSURV1="My String 2";
$NumSURV1=intval($AlphaSURV1);
echo $NumSURV1;
Can you help me to solve that?
Thanks
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.
In order to capture the last group of digits in a string, you can use a regular expression:
This work correctly for all the following cases, including lack of whitespace, leading digits and multiple digits at the end of the string:
Note that if you simply want to get the last character in the string and treat it like a number you can use the following: