I have this string the first is the hours, second minutes, third seconds.
744:39:46
How do I divide the hours ‘744’ in PHP?
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 I’m understanding you correctly, you want to get the substring
'744'from the string'744:39:46'. Since the latter string always has a particular form, you can simply use theexplodefunction to split the string by commas and then take the last element:You can also pick it out with a regular expression by using
preg_match:In the regular expression,
\d+denotes "one or more digits",^denotes the beginning of the string, and$denotes the end of the string. The parentheses around the first\d+allows for capturing of the first set of digits into$matches[1](and$matches[0]is the entire string–ie$matches[0]===$str).