doujiaoang69440 2019-07-31 10:08
浏览 94

PHP:如果返回的日期差异超过X年,则为彩色文本

I'm attempting to create a custom member tag for my forum that will display "X Years of Experience" but with different colors for each individual year, such as red for year one, blue for year two, and so forth.

Getting the date difference was simple enough but I'm stumped on the next bit.

This is the code I currently have:

{{$joinDate = $comment->author()->get_joined(); $currentDate = new \DateTime(); $interval = $joinDate->diff($currentDate); $experience = \IPS\DateTime::formatInterval($interval, 1);}}
<li class="ipsType_light">{$experience} {lang="memberexperience_experience"}</li>
  • 写回答

1条回答 默认 最新

  • dongxi5505 2019-07-31 10:43
    关注

    I am just trying to give you an idea.

    You should create styles.php file in your config folder. And add this below code into this file.

    return [
      'experience' => [
        1 => 'danger',
        2 => 'secondary',
        3 => 'primary'
     ]
    ];
    

    Then in your blade file write this code

    <li class="text-{{config("styles.experience.$experience")}}">{{$experience}} {{lang="memberexperience_experience"}}</li>
    

    If experience is possible to less than 1 year then use below code

    @if($experience < 1)
        <li class="text-danger">{{$experience}}</li>
    @else
        <li class="text-{{config("styles.experience.$experience")}}"> 
           {{$experience}}{{lang="memberexperience_experience"}}</li>
    @endif
    

    Hope this will give you an idea and help you.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器