免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
论坛 程序设计 PHP jj
最近访问板块 发新帖
楼主: vidarz
打印 上一主题 下一主题

jj [复制链接]

论坛徽章:
0
21 [报告]
发表于 2004-01-09 18:03 |只看该作者

XEAM有望在PHP编程领域填补一项国内空白

  1. Current PHP version: 4.3.3
  2. 我们先测试一下 mb_strlen() 函数
  3. 测试的字符串是:English中国人的字
  4. 整个字符串的长度是:
  5. 17
  6. 我们再测试一下 mb_substr() 函数
  7. 测试的字符串是:English中国人的字
  8. 我们只要13个字符,现在变成
  9. English中
复制代码



结果一样。多了一个判断PHP的版本号的,什么意思呢,你的意思是PHP5就可以实现了还是什么?

涉及文件流的处理(打开、写入等)问题就更多了。

论坛徽章:
0
22 [报告]
发表于 2004-01-09 18:10 |只看该作者

XEAM有望在PHP编程领域填补一项国内空白

我开始也以为是版本问题,后来发现是这样的我的php.ini中是这样配的
[mbstring]
; language for internal character representation.
mbstring.language = Simplified Chinese

; internal/script encoding.
; Some encoding cannot work as internal encoding.
; (e.g. SJIS, BIG5, ISO-2022-*)
;mbstring.internal_encoding = EUN-CN


; http input encoding.
mbstring.http_input = pass

; http output encoding. mb_output_handler must be
; registered as output buffer to function
;mbstring.http_output = SJIS

; enable automatic encoding translation accoding to
; mbstring.internal_encoding setting. Input chars are
; converted to internal encoding by setting this to On.
; Note: Do _not_ use automatic encoding translation for
;       portable libs/applications.
;mbstring.encoding_translation = Off

; automatic encoding detection order.
; auto means
;mbstring.detect_order = auto

; substitute_character used when character cannot be converted
; one from another
;mbstring.substitute_character = none;

; overload(replace) single byte functions by mbstring functions.
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
; etc. Possible values are 0,1,2,4 or combination of them.
; For example, 7 for overload everything.
; 0: No overload
; 1: Overload mail() function
; 2: Overload str*() functions
; 4: Overload ereg*() functions
;mbstring.func_overload = 0

跑出来的结果是:

  1. Current PHP version: 4.3.3
  2. 我们先测试一下 mb_strlen() 函数
  3. 测试的字符串是:English中国人的字
  4. 整个字符串的长度是:
  5. 12

  6. 我们再测试一下 mb_substr() 函数
  7. 测试的字符串是:English中国人的字
  8. 我们只要13个字符,现在变成
  9. English中国人
复制代码

论坛徽章:
0
23 [报告]
发表于 2004-01-09 18:26 |只看该作者

XEAM有望在PHP编程领域填补一项国内空白

原帖由 "shukebeita" 发表:
我开始也以为是版本问题,后来发现是这样的我的php.ini中是这样配的
[mbstring]
; language for internal character representation.
mbstring.language = Simplified Chinese

根本不用配置!首先你不能保证服务商是加载该模块,也不能保证是给你配置好的,这需要在程序运行中加载,其实只要在用的函数中加 encode 参数就行了,如: EUC-CN,这样都只是临时性的解决方案,很久以前就有了。但在很多方面(例如我前面讲到的文件流的处理)都是不尽人意的,目前的解决方案也只能做到脚本级的了。

论坛徽章:
0
24 [报告]
发表于 2004-01-09 18:26 |只看该作者

XEAM有望在PHP编程领域填补一项国内空白

原帖由 "mikespook" 发表:
楼主的帖子看上去感觉像给政府的863报告~~~~

能不能多贴点技术上的东西?

http://www.csdn.net/Develop/ArticleImages/23/23161/CSDN_Dev_Image_2004-1-41003000.gif

这个图根本没用~~~你把图里的PHP换成JS..........


比较中肯,明年我们发布的时候仔细研究研究好了,XEAM是开源的:)

论坛徽章:
0
25 [报告]
发表于 2004-01-09 18:58 |只看该作者

XEAM有望在PHP编程领域填补一项国内空白

下面的服务器我租在美国,本来没有这个模块的,mbstring是我要求他们加的,24小时就好了但是默认配的是日语,我只好自己加了一个.htaccess 改成中文了。

http://php.linuxpack.net/mbtest1.php
现在没有感到有什么不方便的

例如我前面讲到的文件流的处理

说来听听,让大伙也长些知识。

论坛徽章:
0
26 [报告]
发表于 2004-01-09 19:26 |只看该作者

XEAM有望在PHP编程领域填补一项国内空白

贴一个XEAM处理文件流的子类的代码,自己看吧

文件:xmTextStream.php
作者:Bighan
更新:2003-12-31
  1. <?php


  2. require_once (dirname(__FILE__). "/xmFsoCommon.php");

  3. class xmTextStream extends xmFsoCommon
  4. {

  5.         var $AtEndOfLine        = false;
  6.         var $AtEndOfStream        = false;
  7.         var $Column                        = fsoPosUnknown;
  8.         var $Line                        = fsoPosUnknown;

  9.         var $Pointer                = fsoPosUnknown;
  10.         var $EOF                        = fsoPosUnknown;
  11.         var $EOL                        = fsoPosUnknown;

  12.         var $Source                        = "";
  13.         var $IsCreate                = true;
  14.         var $IsOverWrite        = false;
  15.         var $OpenMode                = fsoForreading;

  16.         var $_handler                = false;
  17.         var $_IsOpen                = false;
  18.         var $_IsLock                = false;

  19.         var $Unicode                = false;

  20.         function __construct($filename = "", $mode = "rb")
  21.         {
  22.                 parent::__construct();
  23.                 if (!empty($filename) && !empty($mode)) {
  24.                         $this->;OpenFile($filename, $mode);
  25.                 }
  26.         }
  27.         function __destruct()
  28.         {
  29.                 //$this->;Close();
  30.         }
  31.         function OpenFile($filename = "", $mode = "")
  32.         {
  33.                 if ($this->;_IsOpen) return;
  34.                 if (!empty($filename)) $this->;Source = $filename;
  35.                 if (!empty($mode)) $this->;OpenMode = $mode;
  36.                 if ($this->;_handler = &$this->;_doOpenFile()) {
  37.                         $this->;Pointer = 0;
  38.                         $this->;Line                = 0;
  39.                         $this->;Column        = 0;
  40.                         $this->;_CheckEOF();
  41.                         $this->;_IsOpen = true;
  42.                 } else {
  43.                         $this->;Source = "";
  44.                         $this->;OpenMode = fsoForreading;
  45.                 }
  46.                 return $this->;_IsOpen;
  47.         }
  48.         function &_doOpenFile()
  49.         {
  50.                 if (!$this->;Source || !$this->;OpenMode) return false;
  51.                 if ($this->;_IsRemote($this->;Source)) {
  52.                         if (!ini_get('allow_url_fopen')) ini_set('allow_url_fopen', 1);
  53.                 }
  54.                 $fp = false;
  55.                 $this->;_doOpenMode();
  56.                 if ($this->;_doCheckFile()) {
  57.                         if ($this->;OpenMode != 'wb' || $this->;OpenMode != 'wb+') {
  58.                                 $fp = fopen($this->;Source, $this->;OpenMode);
  59.                         } else if ($this->;IsOverWrite) {
  60.                                 $fp = fopen($this->;Source, $this->;OpenMode);
  61.                         }
  62.                 } elseif (($this->;OpenMode != 'rb' || $this->;OpenMode != 'rb+') && $this->;IsCreate) {
  63.                         $fp = fopen($this->;Source, $this->;OpenMode);
  64.                 }
  65.                 return is_resource($fp) ? $fp : false;
  66.         }
  67.         function _doOpenMode()
  68.         {
  69.                 $this->;OpenMode = strtolower(trim($this->;OpenMode));
  70.                 $this->;OpenMode = preg_replace("/^([r|w|a|x])+\s*(b)?\s*(\+)?/i", "\\1b\\3", $this->;OpenMode);
  71.         }
  72.         function _doCheckFile()
  73.         {
  74.                 //$this->;doClearstatcache();
  75.                 $mode = preg_replace("/^([r|w|a|x])+\s*(b)?\s*(\+)?/i", "\\1\\2", $this->;OpenMode);
  76.                 if ($mode == fsoForreading && !$this->;_IsRemote($this->;Source) && !file_exists($this->;Source)) {
  77.                         return false;
  78.                 } elseif (($mode == fsoForwritting || $mode == fsoForappending)
  79.                                 && !file_exists($this->;Source)
  80.                                 && !is_writable(dirname($this->;Source))) {
  81.                         return false;
  82.                 } elseif (($mode == fsoForwritting || $mode == fsoForappending)
  83.                                 && !is_writable(dirname($this->;Source))) {
  84.                         return false;
  85.                 }
  86.                 return true;
  87.         }
  88.         function _Lock($operation)
  89.         {
  90.                 if (!$this->;_IsOpen) return false;
  91.                 return flock($this->;_handler, $operation+LOCK_NB, true);
  92.         }
  93.         function shaLock()
  94.         {
  95.                 $this->;_IsLock = true;
  96.                 return $this->;_Lock(fsoLockShared);
  97.         }
  98.         function excLock()
  99.         {
  100.                 $this->;_IsLock = true;
  101.                 return $this->;_Lock(fsoLockExclusive);
  102.         }
  103.         function unLock()
  104.         {
  105.                 if ($this->;_IsLock) {
  106.                         $this->;_IsLock = false;
  107.                         return $this->;_Lock(fsoLockRelease);
  108.                 }
  109.         }
  110.         function Close()
  111.         {
  112.                 if (!$this->;_IsOpen) return;
  113.                 if ($this->;_IsLock) $this->;unLock();
  114.                 if (is_resource($this->;_handler)) fclose($this->;_handler);
  115.                 $this->;_IsOpen = false;
  116.         }
  117.         function _CheckMode($state)
  118.         {
  119.                 if (ereg('\+', $this->;OpenMode)) return true;
  120.                 $result = false;
  121.                 switch ($state) {
  122.                         case 'r':
  123.                                 if ($this->;OpenMode == fsoForreading) $result = true;
  124.                                 break;
  125.                         case 'w':
  126.                                 if ($this->;OpenMode == fsoForwritting) $result = true;
  127.                                 break;
  128.                         case 'a':
  129.                                 if ($this->;OpenMode == fsoForappending) $result = true;
  130.                                 break;
  131.                 }
  132.                 return $result;
  133.         }
  134.         function _CheckEOF()
  135.         {
  136.                 $this->;EOF = feof($this->;_handler);
  137.                 $this->;AtEndOfStream =& $this->;EOF;
  138.                 return $this->;EOF;
  139.         }
  140.         function _CheckEOL($char)
  141.         {
  142.                 if ($char === "\n" || $char === "\r\n") {
  143.                         $this->;EOL = true;
  144.                         $this->;Line++;
  145.                         $this->;Column = fsoPosEOF;
  146.                 } else {
  147.                         $this->;EOL = false;
  148.                         if ($this->;Column == fsoPosEOF || $this->;Column == fsoPosBOF)
  149.                         {
  150.                                 $this->;Column = 0;
  151.                         }
  152.                         if (ord($char) >; 0x2f) $this->;Column++;
  153.                 }
  154.                 $this->;AtEndOfLine =& $this->;EOL;
  155.                 return $this->;EOL;
  156.         }
  157.         function _CheckPointer()
  158.         {
  159.                 $this->;Pointer = ftell($this->;_handler);
  160.                 return $this->;Pointer;
  161.         }
  162.         function Read($characters)
  163.         {
  164.                 $fileChar = '';
  165.                 if ($characters == 0) return $this->;ReadAll();
  166.                 for ($i = 0; $i < $characters; $i++) {
  167.                         $fileChar .= $this->;ReadChar();
  168.                         if($this->;EOF) break;
  169.                 }
  170.                 return !empty($fileChar) ? $fileChar : false;
  171.         }
  172.         function ReadChar()
  173.         {
  174.                 if (!$this->;_IsOpen || !$this->;_CheckMode('r') || $this->;EOF) return false;
  175.                 $char = '';
  176.                 if ($char = fgetc($this->;_handler)) {
  177.                         if ($this->;Unicode) {
  178.                                 if (ord($char) >; 0x7f) $char .= fgetc($this->;_handler);
  179.                         }
  180.                 }
  181.                 $this->;_CheckPointer();
  182.                 $this->;_CheckEOF();
  183.                 $this->;_CheckEOL($char);
  184.                 return strlen($char) ? $char : false;
  185.         }
  186.         function ReadLine()
  187.         {
  188.                 if (!$this->;_IsOpen || !$this->;_CheckMode('r')) return false;
  189.         $fileString = '';
  190.         while (($fileChar = $this->;ReadChar()) != "\n" && !$this->;EOF) {
  191.             $fileString .= $fileChar;
  192.         }
  193.         return substr($fileString, -1) == "\r" ? substr($fileString, 0, -1) : $fileString;
  194.         }
  195.         function ReadAll()
  196.         {
  197.         $file = '';
  198.         while (!$this->;_CheckEOF()) {
  199.             $file .= fread($this->;_handler, fsoReadDefaultSize);
  200.         }
  201.                 $this->;Line = fsoPosEOF;
  202.                 $this->;Column = fsoPosEOF;
  203.                 $this->;_CheckPointer();
  204.         return $file;
  205.         }

  206.         function Skip($characters)
  207.         {
  208.                 $this->;Move($characters);
  209.         }
  210.         function SkipLine()
  211.         {
  212.                 $this->;ReadLine();
  213.         }
  214.         function Write($string, $length = false)
  215.         {
  216.                 if ($this->;_IsOpen && ($this->;_CheckMode('w') || $this->;_CheckMode('a'))) {
  217.                         if (0 >; $length) return false;
  218.                         if (!$length) $length = strlen($string);
  219.                         if ($bytes = fwrite($this->;_handler, $string, $length)) {
  220.                                 return $bytes;
  221.                         } else {
  222.                                 return false;
  223.                         }
  224.                 }
  225.                 return false;
  226.         }
  227.         function WriteChar($char)
  228.         {
  229.                 if ($this->;_IsOpen && ($this->;_CheckMode('w') || $this->;_CheckMode('a'))) {
  230.                         if ($this->;Unicode) {
  231.                                 $length = (ord($char) < 0x7f) ? 1 : 2;
  232.                         }
  233.                         return $this->;Write($char, $length);
  234.                 }
  235.                 return false;
  236.         }
  237.         function WriteLine($line)
  238.         {
  239.                 $line .= $this->;_LineSeparator;
  240.         return $this->;Write($line);
  241.         }
  242.         /*
  243.         function BufferToStream()
  244.         {
  245.                 return fflush($this->;_handler);
  246.         }
  247.         function StreamToBuffer()
  248.         {
  249.                 return fpassthru($this->;_handler);
  250.         }
  251.         */
  252.         function WriteBlankLines($lines)
  253.         {
  254.         }
  255.         function MoveFirst()
  256.         {
  257.                 if (!$this->;_IsOpen || $this->;Pointer == fsoPosBOF) return false;
  258.                 if(rewind($this->;_handler)) {
  259.                         $this->;Line = 0;
  260.                         $this->;Pointer = 0;
  261.                 }
  262.         }
  263.         function MoveLast()
  264.         {
  265.                 return $this->;Move(-1, SEEK_END);
  266.         }
  267.         function Move($offset, $whence = SEEK_SET)
  268.         {
  269.                 if (!$this->;_IsOpen || $offset == 0) return false;
  270.                 if (($result = fseek($this->;_handler, $offset, $whence)) != -1) {
  271.                         /*
  272.                         if ($this->;Unicode) {
  273.                                 if (ord(fgetc($this->;_handler)) >; 0x7f) {
  274.                                         if ($offset < 0 ) {
  275.                                                 fseek($this->;_handler, -2, $whence);
  276.                                         }
  277.                                 } else {
  278.                                         fseek($this->;_handler, -1, $whence);
  279.                                 }
  280.                         }
  281.                         */
  282.                         $this->;AtEndOfStream = feof($this->;_handler);
  283.                         $this->;Pointer = ftell($this->;_handler);
  284.                 }
  285.                 return ($result === 0) ? true: false;

  286.         }
  287.         function MoveNext()
  288.         {
  289.                 if (!$this->;_IsOpen && $this->;AtEndOfStream) return false;
  290.                 return $this->;Move(1, SEEK_CUR);
  291.         }
  292.         function MovePrevious()
  293.         {
  294.                 if (!$this->;_IsOpen && $this->;AtEndOfStream) return false;
  295.                 return $this->;Move(-1, SEEK_CUR);
  296.         }

  297. }

  298. ?>;
复制代码

论坛徽章:
0
27 [报告]
发表于 2004-01-09 20:52 |只看该作者

XEAM有望在PHP编程领域填补一项国内空白

晕晕,华山论剑~!

论坛徽章:
0
28 [报告]
发表于 2004-01-09 22:05 |只看该作者

XEAM有望在PHP编程领域填补一项国内空白

关于中文的问题可以在台湾的 中研院 找到 补丁代码,准确我不记得在哪里了。

论坛徽章:
0
29 [报告]
发表于 2004-01-09 22:40 |只看该作者

XEAM有望在PHP编程领域填补一项国内空白

放心了,你们慢慢玩吧。大家周末愉快!
longnetpro 该用户已被删除
30 [报告]
发表于 2004-01-09 22:45 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
Chinaunix 论坛 程序设计 PHP jj
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP