note 60031 deleted from function.substr by nlopess

From: Date: Fri, 23 Dec 2005 18:53:12 +0000
Subject: note 60031 deleted from function.substr by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-100629@lists.php.net to get a copy of this message
Note Submitter: risto at adcentral dot pl Reason: useless ---- UTF-8 safe substr define('ENABLE_UTF8_NOMB',true); define('ENABLE_UTF8_MB',false); /** * UTF8 strlen */ function _mb_strlen($s) { if(ENABLE_UTF8_MB) { return mb_strlen($s); } if(ENABLE_UTF8_NOMB) { return strlen(utf8_decode($s)); } return strlen($s); } /** * UTF8 substr */ function _mb_substr($s,$b,$l=NULL) { /* UTF8 ready */ if(ENABLE_UTF8_MB) { return is_null($l) ? mb_substr($s,$b) : mb_substr($s,$b,$l); } /* UTF8 ready */ if(ENABLE_UTF8_NOMB) { if($b < 0 ) { $b = _mb_strlen($s) + (int) $b; } if( is_null($l) || _mb_strlen($s)<($l+$b)) { $l = '*'; } else { if($l < 0 ) $l = _mb_strlen($s) + (int) $l; $l = '{0,'.preg_quote($l).'}'; } preg_match('/^.{'.preg_quote($b).'}(.'.$l.')/us', $s, $m); return ( isset($m[1]) ) ? $m[1] : false; } return ( is_null($l) ) ? substr($s,$b) : substr($s,$b,$l); }

« previous php.notes (#100629) next »