How does PHP make text upside down?

Source: Internet
Author: User
Tags ord

<?PHPHeader("Content-type:text/html;charset=utf-8");$str= "1 Chinese characters utf-8 Code";/** * $b utf-8 with 3, gb2312 with 2*/functionTest$str,$b=3){           $length=strlen($str); $rets= ' ';  for($i= 0;$i<$length;$i++){         if(Ord(substr($str,$i, 1)) >128){             $rets[] =substr($str,$i,$b); $i+=$b-1; }Else{             $rets[] =substr($str,$i, 1); }       }          return implode(‘‘ ,Array_reverse($rets)); } $test= Test ($str);Var_dump($test);/**string (24) "8-FTU 1" in the word "Code series "*/

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >PHP$a= ' abcd min Love Army son ';//the test string, which contains the Chinese language///test output below, because when encoded as Utf-8, a Chinese character occupies 3 lengths//echo strlen (' min ');$b= ' ';$i=0; while($i<strlen($a)){    if(Ord(substr($a,$i, 1)) >0xa0)//The Ord function determines whether the string is Chinese    {       $b=substr($a,$i, 3).$b;//This is a very important sentence, reverse!        $i+=3; }    Else    {      $b=substr($a,$i, 1).$b; $i++; }}Echo $b;?></body>

<?php 
Header ("Content-type:text/html;charset=utf-8");
$STR = "1 Chinese characters utf-8 Code";

/**
* $b utf-8 with 3, gb2312 with 2
*/

Function Test ($str, $b =3) {

$length = strlen ($STR);
$rets = ";

for ($i = 0; $i < $length; $i + +) {
if (Ord (substr ($str, $i, 1)) >128) {
$rets [] = substr ($str , $i, $b);
$i + = $b-1;
}else{
$rets [] = substr ($str, $i, 1);
}
}

Return implode (", Array_reverse ($rets));

}
$test = Test ($STR);
Var_dump ($test);
/**
String (24) "Code 8-FTU 1"
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.