七月 31st, 2007当ajax出现IE错误: -1072896658
当ajax某些调用后,IE出现错误:
system error: -1072896658.
是因为XMLHttpRequest对象请求的文档未指定正确的utf-8编码,就会出现这个错误,PHP文件可以加入:
header( ‘Content-Type: text/html; charset=utf-8′ );
当ajax某些调用后,IE出现错误:
system error: -1072896658.
是因为XMLHttpRequest对象请求的文档未指定正确的utf-8编码,就会出现这个错误,PHP文件可以加入:
header( ‘Content-Type: text/html; charset=utf-8′ );
PHP继承*NIX的一贯传统,完全支持正规表达式的处理。正规表达式提供了一种高级的,但不直观的字符串匹配和处理的方法。用过PERL的正规表达式的朋友都知道,正规表达式的功能非常强大,但学起来不是那么容易。比如:
| ^.+@.+\\..+$ |
这段有效却难以理解的代码足够使一些程序员头痛(我就是)或者让他们放弃使用正规表达式。相信当你读完这个教程后,就可以理解这段代码的含义了。 Read the rest of this entry »
什么是正则表达式 如果原来没有使用过正则表达式,那么可能对这个术语和概念会不太熟悉。不过,它们并不是您想象的那么新奇。 请回想一下在硬盘上是如何查找文件的。您肯定会使用 ? 和 * 字符来帮助查找您正寻找的文件。? 字符匹配文件名中的单个字符,而 * 则匹配一个或多个字符。一个如 \’data?.dat\’ 的模式可以找到下述文件:
data1.dat
data2.dat
datax.dat
dataN.dat
如果使用 * 字符代替 ? 字符,则将扩大找到的文件数量。\’data*.dat\’ 可以匹配下述所有文件名:
data.dat
data1.dat
data2.dat
data12.dat
datax.dat
dataXYZ.dat
尽管这种搜索文件的方法肯定很有用,但也十分有限。? 和 * 通配符的有限能力可以使你对正则表达式能做什么有一个概念,不过正则表达式的功能更强大,也更灵活。
早期起源
正则表达式的“祖先”可以一直上溯至对人类神经系统如何工作的早期研究。Warren McCulloch 和 Walter Pitts 这两位神经生理学家研究出一种数学方式来描述这些神经网络。
1956 年, 一位叫 Stephen Kleene 的数学家在 McCulloch 和 Pitts 早期工作的基础上,发表了一篇标题为“神经网事件的表示法”的论文,引入了正则表达式的概念。正则表达式就是用来描述他称为“正则集的代数”的表达式,因此采用“正则表达式”这个术语。
随后,发现可以将这一工作应用于使用 Ken Thompson 的计算搜索算法的一些早期研究,Ken Thompson 是 Unix 的主要发明人。正则表达式的第一个实用应用程序就是 Unix 中的 qed 编辑器。
如他们所说,剩下的就是众所周知的历史了。从那时起直至现在正则表达式都是基于文本的编辑器和搜索工具中的一个重要部分。 Read the rest of this entry »
今晚玩php,要做字符截取,google到下面这段,收藏一下先。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <?php function c_substr($string, $from, $length = null){ preg_match_all('/[\\x80-\\xff]?./', $string, $match); if(is_null($length)){ $result = implode('', array_slice($match[0], $from)); }else{ $result = implode('', array_slice($match[0], $from, $length)); } return $result; } $str = "zhon华人min共和guo"; $from = 3; $length = 7; echo(c_substr($str, $from, $length)); // 输出: n华人min共 //还有utf-8的 /* Regarding windix's function to handle UTF-8 strings: one can use the "u" modifier on the regular expression so that the pattern string is treated as UTF-8 (available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32). This way the function works for other encodings too (like Greek for example). The modified function would read like this: */ function utf8_substr($str,$start) { $null = ""; preg_match_all("/./u", $str, $ar); if(func_num_args() >= 3) { $end = func_get_arg(2); return join($null, array_slice($ar[0],$start,$end)); } else { return join($null, array_slice($ar[0],$start)); } } ?> |
还有用php里面的strip_tags()可以去除html标记