note 70381 added to function.strrev
| From: | lwc at mytrashmail dot com | Date: | Fri, 13 Oct 2006 20:35:13 +0000 |
| Subject: | note 70381 added to function.strrev | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118508@lists.php.net to get a copy of this message | ||
/*
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);
----
Server IP: 212.199.163.191
Probable Submitter: 88.154.201.216
----
Manual Page -- http://www.php.net/manual/en/function.strrev.php
Edit -- https://master.php.net/note/edit/70381
Del: integrated -- https://master.php.net/note/delete/70381/integrated
Del: useless -- https://master.php.net/note/delete/70381/useless
Del: bad code -- https://master.php.net/note/delete/70381/bad+code
Del: spam -- https://master.php.net/note/delete/70381/spam
Del: non-english -- https://master.php.net/note/delete/70381/non-english
Del: in docs -- https://master.php.net/note/delete/70381/in+docs
Del: other reasons-- https://master.php.net/note/delete/70381
Reject -- https://master.php.net/note/reject/70381
Search -- https://master.php.net/manage/user-notes.php