note 70381 deleted from function.strrev by hholzgra

From: Date: Thu, 02 Aug 2012 11:31:33 +0000
Subject: note 70381 deleted from function.strrev by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189596@lists.php.net to get a copy of this message
Note Submitter: lwc at mytrashmail dot com ---- /* Here's a function that adds to carmel.alex's utf-8 encoding support the ability NOT to reverse numbers (for example when you output a phrase as a parameter for a SWF file that can't handle RTL languages itself, but obviously any numbers should remain the same as in the original phrase). Note that it can be used just as well for UTF-8 usages if you want the numbers to remain intact: */ function utf8_strrev($str, $reverse_numbers) { preg_match_all('/./us', $str, $ar); if ($reverse_numbers) return join('',array_reverse($ar[0])); else { $temp = array(); foreach ($ar[0] as $value) { if (is_numeric($value) && !empty($temp[0]) && is_numeric($temp[0])) { foreach ($temp as $key => $value2) { if (is_numeric($value2)) $pos = ($key + 1); else break; } $temp2 = array_splice($temp, $pos); $temp = array_merge($temp, array($value), $temp2); } else array_unshift($temp, $value); } return implode('', $temp); } } // "It says this site is copyrighted just from 2001" (in Hebrew) $str = "כתוב שהאתר הזה מוגן בזכויות יוצרים רק מאז 2001"; // Reverse everything $str_blind_reverse = utf8_strrev($str, true); // Reverse everything but don't change the year 2001 to 1002... $str_logical_reverse = utf8_strrev($str, false);

« previous php.notes (#189596) next »