From b6bc7daadfa0790d3b4dec66192fbb0ed9e77856 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Mon, 4 Feb 2013 20:17:56 -0700 Subject: [PATCH 1/4] move mb_strlen call out of for loop definition --- include/text.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/text.php b/include/text.php index d1fff85ea3..7163a66404 100644 --- a/include/text.php +++ b/include/text.php @@ -175,7 +175,8 @@ if(! function_exists('xmlify')) { function xmlify($str) { $buffer = ''; - for($x = 0; $x < mb_strlen($str); $x ++) { + $len = mb_strlen($str); + for($x = 0; $x < $len; $x ++) { $char = $str[$x]; switch( $char ) { From 774a78dbded6a8897939fc33d3d5a39079e658dd Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Tue, 5 Feb 2013 23:02:13 -0700 Subject: [PATCH 2/4] better unicode support in xmlify --- include/text.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/text.php b/include/text.php index 7163a66404..03ff32cff9 100644 --- a/include/text.php +++ b/include/text.php @@ -175,9 +175,8 @@ if(! function_exists('xmlify')) { function xmlify($str) { $buffer = ''; - $len = mb_strlen($str); - for($x = 0; $x < $len; $x ++) { - $char = $str[$x]; + $str_array = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY); + foreach($str_array as $char) { switch( $char ) { From 18f71c1050f3333e88b69e0ef18d9bdef3e09190 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Wed, 6 Feb 2013 00:37:15 -0700 Subject: [PATCH 3/4] parsing multi-byte strings with xmlify --- include/text.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/text.php b/include/text.php index 03ff32cff9..075d345cb2 100644 --- a/include/text.php +++ b/include/text.php @@ -175,8 +175,9 @@ if(! function_exists('xmlify')) { function xmlify($str) { $buffer = ''; - $str_array = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY); - foreach($str_array as $char) { + $len = mb_strlen($str); + for($x = 0; $x < $len; $x ++) { + $char = mb_substr($str,$x,1); switch( $char ) { From c886927a52dca84a8908bd169e73ab4c72ebedd3 Mon Sep 17 00:00:00 2001 From: Zach Prezkuta Date: Wed, 6 Feb 2013 22:30:27 -0700 Subject: [PATCH 4/4] use mb_ereg_replace for xmlify and unxmlify --- include/text.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/include/text.php b/include/text.php index 075d345cb2..6f2e977c9c 100644 --- a/include/text.php +++ b/include/text.php @@ -173,7 +173,7 @@ function autoname($len) { if(! function_exists('xmlify')) { function xmlify($str) { - $buffer = ''; +/* $buffer = ''; $len = mb_strlen($str); for($x = 0; $x < $len; $x ++) { @@ -205,7 +205,14 @@ function xmlify($str) { $buffer .= $char; break; } - } + }*/ + + $buffer = mb_ereg_replace("&", "&", $str); + $buffer = mb_ereg_replace("'", "'", $buffer); + $buffer = mb_ereg_replace("\"", """, $buffer); + $buffer = mb_ereg_replace("<", "<", $buffer); + $buffer = mb_ereg_replace(">", ">", $buffer); + $buffer = trim($buffer); return($buffer); }} @@ -215,8 +222,13 @@ function xmlify($str) { if(! function_exists('unxmlify')) { function unxmlify($s) { - $ret = str_replace('&','&', $s); - $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret); +// $ret = str_replace('&','&', $s); +// $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret); + $ret = mb_ereg_replace('&', '&', $s); + $ret = mb_ereg_replace(''', "'", $ret); + $ret = mb_ereg_replace('"', '"', $ret); + $ret = mb_ereg_replace('<', "<", $ret); + $ret = mb_ereg_replace('>', ">", $ret); return $ret; }}