summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-05-20 22:34:48 +0200
committerandi <andi@splitbrain.org>2005-05-20 22:34:48 +0200
commit7d8be2006640e723bf77e0c1a74adf2e672e5246 (patch)
tree4dedb08693e44cc712aac907c3d4ba55d4409f00
parent9a3ea4f82e6365f7045cb2218f2beea5ab8f970d (diff)
downloadrpg-7d8be2006640e723bf77e0c1a74adf2e672e5246.tar.gz
rpg-7d8be2006640e723bf77e0c1a74adf2e672e5246.tar.bz2
fixed problem with utf8_substr and feed generation #340
darcs-hash:20050520203448-9977f-4381d98899e730a301c655b5aae59e83b5580a88.gz
-rw-r--r--feed.php2
-rw-r--r--inc/utf8.php27
2 files changed, 12 insertions, 17 deletions
diff --git a/feed.php b/feed.php
index 8234c81ab..3b58670d5 100644
--- a/feed.php
+++ b/feed.php
@@ -157,7 +157,7 @@ function cleanDesc($desc){
$desc = strip_tags($desc);
$desc = preg_replace('/[\n\r\t]/',' ',$desc);
$desc = preg_replace('/ /',' ',$desc);
- $desc = substr($desc,0,250);
+ $desc = utf8_substr($desc,0,250);
$desc = $desc.'...';
return $desc;
}
diff --git a/inc/utf8.php b/inc/utf8.php
index 3e3edd67f..0b90c8586 100644
--- a/inc/utf8.php
+++ b/inc/utf8.php
@@ -111,24 +111,19 @@ function utf8_strlen($string){
/**
* Unicode aware replacement for substr()
*
- * @todo Handle negative positions etc.
- * @author Harry Fuecks <hfuecks@gmail.com>
+ * @author lmak at NOSPAM dot iti dot gr
+ * @link http://www.php.net/manual/en/function.substr.php
* @see substr()
*/
-function utf8_substr($str, $start, $length=null){
- if ( is_null($length) ) {
- $length = '*';
- } else {
- $length = '{0,'.$length.'}';
- }
- $pattern = '/^.{'.$start.'}(.'.$length.')/us';
- preg_match($pattern, $str, $matches);
-
- if ( isset($matches[1]) ) {
- return $matches[1];
- }
- return false;
-}
+function utf8_substr($str,$start,$length=null){
+ preg_match_all("/./u", $str, $ar);
+
+ if($length != null) {
+ return join("",array_slice($ar[0],$start,$length));
+ } else {
+ return join("",array_slice($ar[0],$start));
+ }
+}
/**
* Unicode aware replacement for explode