Created
November 23, 2008 08:08
-
-
Save wtnabe/28064 to your computer and use it in GitHub Desktop.
feedcreator multibyte patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: include/feedcreator.class.php | |
=================================================================== | |
--- include/feedcreator.class.php (revision 17) | |
+++ include/feedcreator.class.php (working copy) | |
@@ -521,6 +521,9 @@ | |
* @return string the truncated string | |
*/ | |
function iTrunc($string, $length) { | |
+ if (extension_loaded('mbstring')) { | |
+ return FeedCreator::iTrunc_mb($string, $length); | |
+ } | |
if (strlen($string)<=$length) { | |
return $string; | |
} | |
@@ -547,7 +550,33 @@ | |
} | |
+ function iTrunc_mb($string, $length) { | |
+ $encoding = strtoupper($this->encoding); | |
+ if (@mb_strlen($string,$encoding)<=$length) { | |
+ return $string; | |
+ } | |
+ $pos = mb_strrpos($string,".",$encoding); | |
+ if ($pos>=$length-4) { | |
+ $string = mb_substr($string,0,$length-4,$encoding); | |
+ $pos = mb_strrpos($string,".",$encoding); | |
+ } | |
+ if ($pos>=$length*0.4) { | |
+ return mb_substr($string,0,$pos+1,$encoding)." ..."; | |
+ } | |
+ | |
+ $pos = mb_strrpos($string," ",$encoding); | |
+ if ($pos>=$length-4) { | |
+ $string = mb_substr($string,0,$length-4,$encoding); | |
+ $pos = mb_strrpos($string," ",$encoding); | |
+ } | |
+ if ($pos>=$length*0.4) { | |
+ return mb_substr($string,0,$pos,$encoding)." ..."; | |
+ } | |
+ | |
+ return mb_substr($string,0,$length-4,$encoding)." ..."; | |
+ } | |
+ | |
/** | |
* Creates a comment indicating the generator of this feed. | |
* The format of this comment seems to be recognized by |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment