doufuhao0566 2014-12-01 15:37 采纳率: 100%
浏览 29

PHP - 显示问题包括另一个.php文件

I just write simple code to display translated text based on user borowser language. It looks i did something wrong becuase when i use sk.php it display corret SK translate but when it use cs.php it having problem with translate and isntead of any text it just display "s" everywhere.

I was thiking problem can be in translate file so I makde duplicity of sk.php and rename it to cs.php and it didn't help.

Guys is here somebody who can give me an advise where can be a problem?

 public function fetchByVinAxnmrss($con) {
     $success = false;
     if($this->vin){
        $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
        $_SESSION['lang'] = $lang;
        if(isSet($lang))
        {
            setcookie('lang', $lang, time() + (3600 * 24 * 30));
        }
        else if(isSet($_COOKIE['lang']))
        {
            $lang = $_COOKIE['lang'];
        }
        else
        {
            $lang = 'cs';
        } 
        switch ($lang) 
        {
            case 'sk':
            $lang_file = 'sk.php';
            break;
            case 'cs':
            $lang_file = 'cs.php';
            break;
            default:
            $lang_file = 'cs.php';
        }
        include_once 'languages/'.$lang_file;
     try{
        //$sql = "SELECT * FROM `axnmrs_cases` WHERE `vin` = ':vin' ORDER BY STR_TO_DATE(date_created, '%Y-%m-%d %H:%i:%s') LIMIT 30";
        $sql = "SELECT * FROM axnmrs_cases WHERE vin = :vin ORDER BY date_created DESC LIMIT 60";
        $stmt = $con->prepare( $sql );
        $stmt->bindValue( "vin", $this->vin, PDO::PARAM_STR );
        $stmt->execute();
            while ($row = $stmt->fetch()){
            echo $lang_file;    
            echo  "<dd>".$lang['YES']."</dd>"

p.s. I am debuging with that echo $ lang_file to see which file are opening.

EDIT: adding part of my cs.php file:

$lang = array();

//All
$lang['YES'] = 'Ano';
$lang['NO'] = 'Ne';
$lang['NOT_AVALIABLE'] = 'Není k dispozici';
$lang['CURRENCY'] = 'Měna';
  • 写回答

1条回答 默认 最新

  • duanji5116 2014-12-01 15:44
    关注

    $lang is not an array. You've made it a string, and PHP does let you treat a string as an array. e.g.

    $foo = 'This is a test';
            01234567890123
    
    echo $foo[6]; // outputs s
    

    Since you're getting c everywhere, it's probably because:

    $lang = 'cs';
             01
    
    echo $lang['YES'];
    becomes 
    echo $lang[0];
    becomes
    echo 'c';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错