dqndc26628 2017-03-17 02:54
浏览 6
已采纳

通过那里没有任何东西是有价值的(生日)

if ($_SERVER["REQUEST_METHOD"] == "POST") {

        $email          = $_POST['email'];
        $viewemail      = $_POST['viewemail'];
        $gender         = $_POST['gender'];
        $birthdayyear   = 0 + $_POST['birthdayyear'];
        $birthdaymonth  = 0 + $_POST['birthdaymonth'];
        $birthdayday    = 0 + $_POST['birthdayday'];
        $country        = 0 + $_POST['country'];
        $lang       = 0 + $_POST['lang'];
        $favpet     = $_POST['favpet'];

        if (strlen($birthdayyear) == 2)  {
        $fourdig = date_create_from_format('y', $birthdayyear);
        $birthdayyear = date_format($fourdig, 'Y');
        if ($birthdayyear > date('Y'))
        $birthdayyear = $birthdayyear - 100;
        }


    die($birthdayyear);

the page will not display the value, but if i write die('sd'.$birthdayyear); I'll get "sd1988". This is when I'm posting the value "1988" but for some reason it works if I just post "88".. So what am I'm doing wrong?

Thanks

  • 写回答

4条回答 默认 最新

  • douweiluo0600 2017-03-17 12:15
    关注

    Added "0 + (int)$_POST[]" was the right solution to this. thanks Shane Henry. Anyway, heres the working code if someone wants it

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $birthdayyear   = 0 + (int)$_POST['birthdayyear'];
    $birthdaymonth  = 0 + (int)$_POST['birthdaymonth'];
    $birthdayday    = 0 + (int)$_POST['birthdayday'];
    
        if (strlen($birthdayyear) == 2)  { // if the year value is "88", it will convert it to a four digit number.
            $birthdayyear = date_format(date_create_from_format('y', $birthdayyear), 'Y');
        if ($birthdayyear > date('Y')) // if the year is over the present year
            $birthdayyear = $birthdayyear - 100; // 2035 will become 1935
        }
    
    $birthday = date("Ymd", strtotime($birthdayyear.'-'.$birthdaymonth.'-'.$birthdayday)); // returns "YYYYmmdd"
    echo $birthday;
    }
    

    Thanks for all the help guys!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测