/** Unlike substr, handles case where $string is too short.
* @param $string
* @param $nChars - negative to return at end of string.
*/
function safe_substr($string, $nChars) {
if ($nChars == 0 || !isset($string))
return "";
if (strlen($string) <= abs($nChars))
// $string is too short (or exactly the desired length). Return the string.
return $string;
return substr($string, $nChars);
}