°uº¬ºº×Ö×Ö*u´®ÂÒÂe
PHPÃaeÊÔÌa£¬ÌaÄ¿ºÜ¶Ì£¬Ò²ºÜ³£¼u£¬µ«¸uÈÝÒ׳o´i£¬ÌaÄ¿ÈçÏÂ
ÈçºÎʵÏÖ×Öu´®×ª£¿
µÚÒ»´Ó¦£¬µ±È»ÊÇstrrevº¯ÊýÀ²£¬ÕaôÈÝÒ×µÄÌaÄ¿»¹ÅÔÚÃaeÊÔÀi¿¼£¬Õae²»ÏÓÂe³°¡£¿µ«ÊÇ¿´ÁËÍøÉϵĴ𰸺o£¬¢ÏÖ×Ô¼º´iÁË~~~
strrevº¯Êý¶ÔÓ¢ÎĺܺÃÓã¬Ö±½Ó¿ÉÒÔʵÏÖ×Öu´®×ª£¬µ«ÊÇÃae¶ÔÖÐÎÄÄØ£¿¿Ï¶¨¶¼ÊÇÂÒÂe£¬¶ÔÓÚÕaÑuµÄÎÊÌaÓкܶa£¬±ÈÈçstrstr£¬substrµÈº¯Êý¶¼ÊÇÕaÑuµÄ¡£»¹ºÃPHPÌa¹(C)ÁËmb_ÀaµÄº¯ÊýʵÏÖ²»Í¬±aÂe¡¢²»Í¬ÓiÑÔÖ®¼aµÄÏa»¥×ª»»µÈ²Ù×÷¡£ÏÂÃaeÊÇÎÒдµÄPHP×Öu´®×ªº¯Êý£¨mb_ÀaµÄº¯ÊýÐeÒª¿ªÆoÒ»¸omb_stringʵÏÖ£(C)¡£
*½a¾o½°¸**
´uÂe£º
<?php
header("content-type:text/html;charset=utf-8");
/**
strrev() º¯Êý*´×ª×Ö*u´®¡£
Ói*¨
strrev(string)
²ÎÊý ÃeÊo
string ±ØÐe¡£¹ae¶¨Òª*´×ªµÄ×Ö*u´®¡£
*/
/**
´Ëº¯ÊýµÄ×÷ÓÃÊÇ*´×ªÖÐÎÄ×Ö*u´®
mb_strlen() »ñÈ¡×Ö*uµÄ³¤¶È
mb_substr() »ñÈ¡×Ö*uµÄµ¥¸oÔªËØ
krsort() °´ÕÕ¼uÖµÄaeÐoÅÅÐoÊý×e,¶Ô¹ØÁªÊý×e°´ÕÕ¼uÃu½øÐнµÐoÅÅÐo
Array ( [8] => ¹u [7] => ÖÐ [6] => h [5] => s [4] => i [3] => l [2] => g [1] => n [0] => E ) EnglishÖйu->¹uÖÐhsilgnE
(ksort()¶Ô¹ØÁªÊý×e°´ÕÕ¼uÃu½øÐÐÉýÐoÅÅÐo)
implode() ½«Êý×eÆ´½ÓΪ×Ö*u´®
explode() ʹÓÃ×Ö*u´®*Ö¸o×Ö*u´®
*/
function str_rev_gb($str){
//ÅжÏÊaÈeµÄÊDz»ÊÇutf8ÀaÐ͵Ä×Ö*u£¬*ñÔoÍ˳o
if(!is_string($str)||!mb_check_encoding($str,'UTF-8')){
exit("ÊaÈeÀaÐͲ»ÊÇUTF8ÀaÐ͵Ä×Ö*u´®");
}
$array=array();
//½«×Ö*u´®´aeÈeÊý×e
$l=mb_strlen($str,'UTF-8');//ÔÚmb_strlen¼ÆËaʱ£¬Ñ¡¶¨ÄÚÂeΪUTF8£¬Ôo»a½«Ò»¸oÖÐÎÄ×Ö*uµ±×÷³¤¶È1À´¼ÆËa
for($i=0;$i<$l;$i++){
$array[]=mb_substr($str,$i,1,'UTF-8');
}
//*´×ª×Ö*u´®
krsort($array);
//Æ´½Ó×Ö*u´®
$string=implode($array);
return $string;
}
$str1 = "Englist";
$str2 = "EnglishÖйu";
$str3 = "EngÖÐlish¹u";
$str4 = "ÖлªÈËÃñ¹²ºÍ¹u";
echo 'Ö±½ÓÓÃPHP×Ô´østrrevº¯Êý*´×ª£º'.'<br />';
echo $str1."->".strrev($str1)."<br>";
echo $str2."->".strrev($str2)."<br>";
echo $str3."->".strrev($str3)."<br>";
echo $str4."->".strrev($str4)."<br>";
echo '<br />';
echo $str1."->".str_rev_gb($str1)."<br>";
echo $str2."->".str_rev_gb($str2)."<br>";
echo $str3."->".str_rev_gb($str3)."<br>";
echo $str4."->".str_rev_gb($str4)."<br>";
ÔËÐнa¹u£º
Ö±½ÓÓÃPHP×Ô´østrrevº¯Êý*´×ª£º
Englist->tsilgnE
EnglishÖйu->��ŒW�hsilgnE
EngÖÐlish¹u->���hsil���gnE
ÖлªÈËÃñ¹²ºÍ¹u->��…A¾Ó…eÄç䎍ŒW�
Englist->tsilgnE
EnglishÖйu->¹uÖÐhsilgnE
EngÖÐlish¹u->¹uhsilÖÐgnE
ÖлªÈËÃñ¹²ºÍ¹u->¹uºÍ¹²ÃñÈË»ªÖÐ
ÐeҪעÒaµÄÊÇ£¬mb_strlen²¢²»ÊÇPHPºËÐĺ¯Êý£¬Ê¹ÓÃÇ°ÐeҪȱ£ÔÚphp.iniÖмÓÔØÁËphp_mbstring.dll£¬¼´È±£¡°extension=php_mbstring.dll¡±ÕaÒ»ÐдaeÔÚ²¢ÇÒûÓб»×¢Ê͵o£¬*ñÔo»a³oÏÖ䶨Òaº¯ ÊýµÄÎÊÌa¡£
ÒÔÉϾÍÊDZ¾ÎĵÄÈ«²¿ÄÚÈÝ£¬Ï£Íu¶Ô´o¼ÒµÄѧϰÓÐËu°iÖu£¬Ò²Ï£Íu´o¼Ò¶a¶aÖ§³Ö½Å±¾Ö®¼Ò¡£