$sub1 = 0+substr($text, 0, 3);
$sub2 = 0+substr($text, 3, 6);
$sub3 = 0+substr($text, 6, 9);
$sum = 0+$sub1+$sub2+$sub3;
echo $sum;
Basically, $text is a string of numbers that looks something like: 296294255268313 and so on.
Then I use substr to get the first three digits/letters of $text (296) and then the second three digits/letters of $text(294) and the third (255). I add 0 to each of these strings so that PHP can automatically cast it into an integer. This works fine.
However, when I then go to add these integers together and put it inside variable $sum, everything goes awry. It outputs a weird (and very large) number. So then I decided to test if it was possible to add integers to strings with the following code:
$sub1 = 294+255+substr($text, 0, 3);
echo $sub1;
And this, to my surprise, outputted the correct sum (845). Does anyone know how this happened or how it can be fixed? Thanks. =]


