How would i split a string every 4 characters and then have every 4 characters put into a separate variable so i can do other stuff with each individual 4 characters?
Share
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.
Well, I don’t really see you putting each of them in a different variable, because then you’ll have like 10 variables:
But you could use the
str_splitfunction as following:$variable = str_split($origionalvar, 4);it will create an array, which you can access:
$variable[0]to$variable[sizeof(variable)]If you don’t know about arrays, you really should read up on those. They are really great if you want to store a lot of similar information in an object and you don’t want to create a new variable for it every time. Also you can loop over them very easily and do some other great stuff with them.
I assume you probably googled this question a bit too. You must have come across http://php.net/manual/en/function.str-split.php. Did you see this page, and if you did, did you have some trouble with it. If so perhaps we can help you reading the documentation properly.