+ -
当前位置:首页 → 问答吧 → 《PHP5 项目实战开发详解》第147页有错误

《PHP5 项目实战开发详解》第147页有错误

时间:2008-03-11

来源:互联网

3.函数strncmp(), strncmp(string1,string2,length)

<?php
    if(strncmp("phpchina","phplinux",3))
    {
     echo "ok";
    }
    else {
     echo "next";
    }
?>  
结果:ok  //比较前三位,得数据

正确结果应该为:next      //前三位相等,返回0;

<?php
    if(strncmp("phpchina","phplinux",4))
    {
     echo "ok";
    }
    else {
     echo "next";
    }
?>  
结果:next   //比较前四位的数据

正确结果应该为:ok       //c的ASCII码小于l的ASCII码,返回负数;

第149页可能是印刷错误吧,字符串查找函数返回位置是strpos; 书中写成strops;

[ 本帖最后由 636826 于 2008-3-12 11:00 编辑 ]

作者: 636826   发布时间: 2008-03-11

int strncmp ( string str1, string str2, int len )


This function is similar to strcmp(), with the difference that you can specify the (upper limit of the) number of characters (len) from each string to be used in the comparison.

Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

Note that this comparison is case sensitive.

作者: grac   发布时间: 2008-03-11

Therefor ,you are right..

作者: grac   发布时间: 2008-03-11

楼上的怎么尽说英语啊。。。

作者: cnyangqi   发布时间: 2008-03-17

谢谢LZ! 我们会勘误!

作者: 疯狂小猫   发布时间: 2008-03-20

热门下载

更多