dousui3124 2015-06-13 23:27
浏览 45
已采纳

IF语句与mb_strlen的组合不起作用[关闭]

I have a form with following if-statement's but it doesn't work. The First verification "If empty" does work but not the second one with mb_strlen, why?

That's my PHP-Code:

elseif(empty($_POST['project_title']) OR 
(mb_strlen($_POST['project_title'], 'UTF-8') <= 3)){
echo "Please correct the Project Title";}

I don't get also any error. Do I have some Syntax mistakes in my Code?

  • 写回答

1条回答 默认 最新

  • doucheng9304 2015-06-13 23:47
    关注

    From what I can tell, your code works fine. This little test script I ran:

    <?php
    
    echo test_title( '' );
    echo test_title( 'pdf' );
    echo test_title( 'This one works' );
    
    function test_title( $title ) {
    
       echo "testing '$title'. ";
    
       if( empty( $title ) ||
           mb_strlen( $title, 'UTF-8') <= 3
         ){
            return "Please correct the Project Title
    ";
         }
    
       return "looks fine
    ";
    }
    

    Will output the following:

    testing ''. Please correct the Project Title
    testing 'pdf'. Please correct the Project Title
    testing 'This one works'. looks fine
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画