dongwei3866 2013-03-31 01:17
浏览 8
已采纳

php中的字符串比较

In my project, mysql table value need to be updated, so when user see his/her profile then he/she can update his/her profile, after click the 'update profile' button he/she would see a form which fill with previous data and then he may change his profile or not. I want to check if he/she update information or not, so I fetch that user information from database and check the present information that he/she enter, if values change, then store that changed value on other array and store only that changed information. So I use strcmp( str1, str2) function but it doesn't work, so I use "===" it works only for small data such as name, password etc. But I need also to check if he/she change his/her biography or not, I use that function but it doesn't work.

My code ::

  <?php
          $users = $user->user_info_by_id($object->id);  // get user's info from database

          foreach( $users as $user )  {  // 
            if( $user->user_name === $arrayValue['user_name'] )  // here $arrayValue['user_name'] is the recent info that user sent to update his profile 
                echo "<br /> value matched";   // it matched
            else {
                echo "<br /> value not matched";
            }

            if( $user->user_biography === $arrayValue['user_biography'] ) // it doesn't work, here 'user_biography' is 'text' type data in mysql database
                echo "<br /> value matched";
            else 
                echo "<br /> value not matched";  // answer is always 'value not matched'
        }

   ?>  
  • 写回答

1条回答 默认 最新

  • dtbhp60824 2013-03-31 02:06
    关注

    strcasecmp should do the job. I know you mentioned on your answer that you tried strcmp and it didn't work but you did not mention or showed how you were using it.

    Try:

    if($user->user_biography === trim($arrayValue['user_biography']) != 0) {
       // user_name changed. 
     } else {
       //user_name did not change
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路