dongmen5867 2014-09-17 10:25
浏览 62
已采纳

需要更改字符串的大小写 - PHP

$variable = "test_company_insurance_llc_chennai_limited_w-8tyu.pdf";

I need to display above the $variable like

Test Company Insurance LLC Chennai Limited W-8TYU.pdf

For that I've done:

$variable = str_replace("_"," ","test_company_insurance_llc_chennai_limited_w-8tyu.pdf");

$test  = explode(" ", $variable);
$countof = count($test);

for ($x=0; $x<$countof; $x++) {

    if($test[$x] == 'w-8tyu' || $test[$x] == 'llc') {
       $test[$x] = strtoupper($test[$x]);
       //todo
    }   

} 

I've got stuck in the to-do part.

I will change the specific words to uppercase using strtoupper.

Later, how should I need to merge the array?

Any help will be thankful...

  • 写回答

3条回答 默认 最新

  • dongyixiu3110 2014-09-17 10:32
    关注
    $str_in = "test_company_insurance_llc_chennai_limited_w-8tyu.pdf";
    $lst_in = explode("_", $str_in);
    $lst_out = array();
    foreach ($lst_in as $val) {
        switch($val) {
            case "llc"          : $lst_out[] = strtoupper($val);
                                  break;
            case "w-8tyu.pdf"   : $lst_temp = explode('.', $val);
                                  $lst_out[] = strtoupper($lst_temp[0]) . "." . $lst_temp[1];
                                  break;
            default             : $lst_out[] = ucfirst($val);
        }
    }
    $str_out = implode(' ', $lst_out);
    echo $str_out;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?