Going a bit OT here, but if $string is undefined
code:
$snippet = substr("$string",1,5)

Will return "$stri", probably not what you are after.

A better way of handling it is probably:
code:
$snippet = substr("" + $string,1,5)