I'm not saying this is your problem, but why do you use quotes on this line?

$string1 = substr("$string",1,$spot-1)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.