PHP
·
发表于 5年以前
·
阅读量:8296
±¾ÎÄʵÀý½²ÊoÁËPHPʹÓÃstrrevתÖÐÎÄÂÒÂeÎÊÌaµÄ½a¾o½¨¡£ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º
ÔÚÓÃPHPÖеÄstrrve*תÖÐÎÄʱ£¬»a³oÏÖÂÒÂeÇe¿o
ÀýÈ磺
header("Content-Type: text/html; charset=utf-8");
echo strrev("´¦ÀiʹÓÃstrrev()º¯ÊýʱµÄÂÒÂeÎÊÌa")."<br>";
ÔËÐнa¹uΪ£º
��o[ßh»s䄚½Ÿeai�)(verrts��ÂP䆐Ÿr�
½a¾o½¨¾ÍÊÇ×Ô¼ºÖØдһ¸ocnstrrevµÄº¯Êý
header("Content-Type: text/html; charset=utf-8");
$str = '´¦ÀiʹÓÃstrrev()º¯ÊýʱµÄÂÒÂeÎÊÌa';
function cnstrrev($str)
{
$len = strlen($str);
for($i = 0; $i < $len; $i++)
{
$char = $str{0};
if(ord($char) > 127) //ord()º¯ÊýÈ¡µÃµÚÒ»¸o×Ö*uµÄASCIIÂe£¬Èç¹u´oÓÚ0xa0(127)µÄ»°ÔoÊÇÖÐÎÄ×Ö*u
{
$i+=2;//utf-8±aÂeµÄÇe¿oÏ£¬Ò»¸oÖÐÎÄ×Ö*uÕ¼Èý¸o×Ö½Ú
if($i < $len)
{
$arr[] = substr($str, 0, 3);//utf-8±aÂeµÄÇe¿oÏ£¬Ò»¸oÖÐÎÄ×Ö*uÕ¼Èý¸o×Ö½Ú
$str = substr($str, 3);
}
}
else
{
$arr[] = $char;
$str = substr($str, 1);//*ñÔoΪ*ÇÖÐÎÄ£¬Õ¼Ò»¸o×Ö*u
}
}
return join(array_reverse($arr));//ÒÔÏa*´µÄÔªËØ˳Ðo*µ»ØÊý×e£º
}
echo $str.'+'.cnstrrev($str);
ÔËÐнa¹uΪ£º
´¦ÀiʹÓÃstrrev()º¯ÊýʱµÄÂÒÂeÎÊÌa+ÌaÎÊÂeÂÒµÄʱÊýº¯)(verrtsÓÃʹÀi´¦
¸u¶a¹ØÓÚPHPÏa¹ØÄÚÈݸÐÐËȤµÄ¶ÁÕ߿ɲe¿´±¾Õ¾×¨Ìa£º¡¶php³£Óú¯ÊýÓe¼¼ÇÉ×ܽa¡¡¢¡¶[php×Öu´®(string)Óè×ܽa](http://www.jb51.net/Special/47.htm)¡¡¢¡¶PHPÊý×e(Array)²Ù×÷¼¼ÇÉ´oÈ«¡¡¢¡¶[PHP»u±¾Ói¨ÈeÃŽ̳Ì](http://www.jb51.net/Special/348.htm)¡¡¢¡¶php+mysqlÊý¾Ý¿a²Ù×÷ÈeÃŽ̡̳¼°¡¶php³£¼uÊý¾Ý¿a²Ù×÷¼¼ÇÉ»a×Ü¡*
Ï£Íu±¾ÎÄËuÊo¶Ô´o¼ÒPHP³ÌÐoÉe¼ÆÓÐËu°iÖu¡£