码迷,mamicode.com
首页 > 其他好文 > 详细

strtr函数的用法

时间:2014-10-08 23:17:37      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   sp   div   c   

http://php.net/manual/en/function.strtr.php

<?php
$trans = array("h" => "-", "hello" => "hi", "hi" => "hello");
echo strtr("hi all, I said hello", $trans);
?>

The above example will output:
hello all, I said hi

 

function q2b($mstring)
{
$mstring = @preg_replace(‘/([\x80-\xFF])([\x80-\xFF])/xe‘, ‘(ord(substr(\1,0,1))==163&&(ord(substr(\2,1,2))>=161||ord(substr(\2,1,2))<=254)?chr(ord(\2)-0x80):\1\2)‘, $mstring);
$mstring = @preg_replace(‘/\xa3([\xa1-\xfe])/e‘, ‘chr(ord(\1)-0x80)‘, $mstring);

$arr = array(‘0‘ => ‘0‘, ‘1‘ => ‘1‘, ‘2‘ => ‘2‘, ‘3‘ => ‘3‘, ‘4‘ => ‘4‘,‘5‘ => ‘5‘, ‘6‘ => ‘6‘, ‘7‘ => ‘7‘, ‘8‘ => ‘8‘, ‘9‘ => ‘9‘, ‘A‘ => ‘A‘, ‘B‘ => ‘B‘, ‘C‘ => ‘C‘, ‘D‘ => ‘D‘, ‘E‘ => ‘E‘,‘F‘ => ‘F‘, ‘G‘ => ‘G‘, ‘H‘ => ‘H‘, ‘I‘ => ‘I‘, ‘J‘ => ‘J‘, ‘K‘ => ‘K‘, ‘L‘ => ‘L‘, ‘M‘ => ‘M‘, ‘N‘ => ‘N‘, ‘O‘ => ‘O‘,‘P‘ => ‘P‘, ‘Q‘ => ‘Q‘, ‘R‘ => ‘R‘, ‘S‘ => ‘S‘, ‘T‘ => ‘T‘,‘U‘ => ‘U‘, ‘V‘ => ‘V‘, ‘W‘ => ‘W‘, ‘X‘ => ‘X‘, ‘Y‘ => ‘Y‘,‘Z‘ => ‘Z‘, ‘a‘ => ‘a‘, ‘b‘ => ‘b‘, ‘c‘ => ‘c‘, ‘d‘ => ‘d‘,‘e‘ => ‘e‘, ‘f‘ => ‘f‘, ‘g‘ => ‘g‘, ‘h‘ => ‘h‘, ‘i‘ => ‘i‘,‘j‘ => ‘j‘, ‘k‘ => ‘k‘, ‘l‘ => ‘l‘, ‘m‘ => ‘m‘, ‘n‘ => ‘n‘,‘o‘ => ‘o‘, ‘p‘ => ‘p‘, ‘q‘ => ‘q‘, ‘r‘ => ‘r‘, ‘s‘ => ‘s‘, ‘t‘ => ‘t‘, ‘u‘ => ‘u‘, ‘v‘ => ‘v‘, ‘w‘ => ‘w‘, ‘x‘ => ‘x‘, ‘y‘ => ‘y‘, ‘z‘ => ‘z‘,‘(‘ => ‘(‘, ‘)‘ => ‘)‘, ‘〔‘ => ‘[‘, ‘〕‘ => ‘]‘, ‘【‘ => ‘[‘,‘】‘ => ‘]‘, ‘〖‘ => ‘[‘, ‘〗‘ => ‘]‘, ‘“‘ => ‘[‘, ‘”‘ => ‘]‘,‘‘‘ => ‘[‘, "‘" => ‘]‘, ‘{‘ => ‘{‘, ‘}‘ => ‘}‘, ‘《‘ => ‘<‘,‘》‘ => ‘>‘,‘%‘ => ‘%‘, ‘+‘ => ‘+‘, ‘—‘ => ‘-‘, ‘-‘ => ‘-‘, ‘~‘ => ‘-‘,‘:‘ => ‘:‘, ‘。‘ => ‘.‘, ‘、‘ => ‘,‘, ‘,‘ => ‘.‘, ‘、‘ => ‘.‘, ‘;‘ => ‘,‘, ‘?‘ => ‘?‘, ‘!‘ => ‘!‘, ‘…‘ => ‘-‘, ‘‖‘ => ‘|‘, ‘”‘ => ‘"‘, "‘" => ‘`‘, ‘‘‘ => ‘`‘, ‘|‘ => ‘|‘, ‘〃‘ => ‘"‘,‘ ‘ => ‘ ‘);


$mstring = strtr($mstring, $arrstrtr);

return $mstring;
}  

strtr函数的用法

标签:style   blog   http   color   io   ar   sp   div   c   

原文地址:http://www.cnblogs.com/wangkongming/p/4011359.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!