changeset 116:f268d7d10590

fix: マルチバイトmb_str_replaceをネットからいただいて追加
author yoneda <epgrec@park.mda.or.jp>
date Sat, 13 Mar 2010 23:30:11 +0900
parents 7a64d5e3baee
children f5d58cf2842f cb04c9ca1cb0
files Reservation.class.php reclib.php
diffstat 2 files changed, 48 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/Reservation.class.php	Sat Mar 13 23:00:51 2010 +0900
+++ b/Reservation.class.php	Sat Mar 13 23:30:11 2010 +0900
@@ -200,38 +200,38 @@
 			$day_of_week = array( "","","","羂","","","" );
 			$filename = $settings->filename_format;
 			
+			// %TITLE%
+			$filename = mb_str_replace("%TITLE%", $fn_title, $filename);
+			// %ST%	紮ユ
+			$filename = mb_str_replace("%ST%",date("YmdHis", $start_time), $filename );
+			// %ET%	腟篋ユ
+			$filename = mb_str_replace("%ET%",date("YmdHis", $end_time), $filename );
+			// %TYPE%	GR/BS
+			$filename = mb_str_replace("%TYPE%",$crec->type, $filename );
+			// %CH%	c潟
+			$filename = mb_str_replace("%CH%","".$crec->channel, $filename );
+			// %DOW%	ワSun-Mon鐚
+			$filename = mb_str_replace("%DOW%",date("D", $start_time), $filename );
+			// %DOWJ%	ワ-鐚
+			$filename = mb_str_replace("%DOWJ%",$day_of_week[(int)date("w", $start_time)], $filename );
+			// %YEAR%	紮綛
+			$filename = mb_str_replace("%YEAR%",date("Y", $start_time), $filename );
+			// %MONTH%	紮
+			$filename = mb_str_replace("%MONTH%",date("m", $start_time), $filename );
+			// %DAY%	紮
+			$filename = mb_str_replace("%DAY%",date("d", $start_time), $filename );
+			// %HOUR%	紮
+			$filename = mb_str_replace("%HOUR%",date("H", $start_time), $filename );
+			// %MIN%	紮
+			$filename = mb_str_replace("%MIN%",date("i", $start_time), $filename );
+			// %SEC%	紮腱
+			$filename = mb_str_replace("%SEC%",date("s", $start_time), $filename );
+			// %DURATION%	牙紙鐚腱鐚
+			$filename = mb_str_replace("%DURATION%","".$duration, $filename );
+			
 			// √絖_
 			$fn_title = mb_ereg_replace("[ \./\*:<>\?\\|()\'\"&]","_", trim($title) );
 			
-			// %TITLE%
-			$filename = str_replace("%TITLE%", $fn_title, $filename);
-			// %ST%	紮ユ
-			$filename = str_replace("%ST%",date("YmdHis", $start_time), $filename );
-			// %ET%	腟篋ユ
-			$filename = str_replace("%ET%",date("YmdHis", $end_time), $filename );
-			// %TYPE%	GR/BS
-			$filename = str_replace("%TYPE%",$crec->type, $filename );
-			// %CH%	c潟
-			$filename = str_replace("%CH%","".$crec->channel, $filename );
-			// %DOW%	ワSun-Mon鐚
-			$filename = str_replace("%DOW%",date("D", $start_time), $filename );
-			// %DOWJ%	ワ-鐚
-			$filename = str_replace("%DOWJ%",$day_of_week[(int)date("w", $start_time)], $filename );
-			// %YEAR%	紮綛
-			$filename = str_replace("%YEAR%",date("Y", $start_time), $filename );
-			// %MONTH%	紮
-			$filename = str_replace("%MONTH%",date("m", $start_time), $filename );
-			// %DAY%	紮
-			$filename = str_replace("%DAY%",date("d", $start_time), $filename );
-			// %HOUR%	紮
-			$filename = str_replace("%HOUR%",date("H", $start_time), $filename );
-			// %MIN%	紮
-			$filename = str_replace("%MIN%",date("i", $start_time), $filename );
-			// %SEC%	紮腱
-			$filename = str_replace("%SEC%",date("s", $start_time), $filename );
-			// %DURATION%	牙紙鐚腱鐚
-			$filename = str_replace("%DURATION%","".$duration, $filename );
-			
 			// 絖潟若紊
 			if( defined("FILESYSTEM_ENCODING") ) {
 				$filename = mb_convert_encoding( $filename, FILESYSTEM_ENCODING, "UTF-8" );
--- a/reclib.php	Sat Mar 13 23:00:51 2010 +0900
+++ b/reclib.php	Sat Mar 13 23:30:11 2010 +0900
@@ -21,4 +21,23 @@
          "// -->\n</script>" );
 }
 
+// ゃstr_replace
+
+function mb_str_replace($search, $replace, $target, $encoding = "UTF-8" ) {
+	$notArray = !is_array($target) ? TRUE : FALSE;
+	$target = $notArray ? array($target) : $target;
+	$search_len = mb_strlen($search, $encoding);
+	$replace_len = mb_strlen($replace, $encoding);
+	
+	foreach ($target as $i => $tar) {
+		$offset = mb_strpos($tar, $search);
+		while ($offset !== FALSE){
+			$tar = mb_substr($tar, 0, $offset).$replace.mb_substr($tar, $offset + $search_len);
+			$offset = mb_strpos($tar, $search, $offset + $replace_len);
+		}
+		$target[$i] = $tar;
+	}
+	return $notArray ? $target[0] : $target;
+}
+
 ?>
\ No newline at end of file