Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Created November 23, 2008 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtnabe/28064 to your computer and use it in GitHub Desktop.
Save wtnabe/28064 to your computer and use it in GitHub Desktop.
feedcreator multibyte patch
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