I have a string say: Order_num = \"0982asdlkj\"
How can I split that into the 2 variables, with the number element and then another variable with the le
Use preg_match() with a regular expression of (\d+)([a-zA-Z]+)
. If you want to limit the number of digits to 1-4 and letters to 6-9, change it to (\d+{1,4})([a-zA-Z]{6,9})
.
preg_match("/(\\d+)([a-zA-Z]+)/", "0982asdlkj", $matches);
print("Integer component: " . $matches[1] . "\n");
print("Letter component: " . $matches[2] . "\n");
Outputs:
Integer component: 0982
Letter component: asdlkj
http://ideone.com/SKtKs