//MFB_CH.php
<?php
class MFB_CH{
static function GetMFB_ChTxt($index)
{
if(array_key_exists($index,self::$MFB_ChTxt))
{
return self::$MFB_ChTxt[$index];
}else{
return "";
}
}
//汉化准备
private static $MFB_ChTxt = array("Title"=>"Hello",
"Age"=>"World");
}
?>
//test.php
<?php include'MFB_CH.php';
//需要汉化的文件
//测试 1、key 存在时和key不存在时
echo MFB_CH::GetMFB_ChTxt('Title');
$test = MFB_CH::GetMFB_ChTxt('test');
if($test == ""){
echo "this key is not exit in the array";
}
?>
本文介绍了一个简单的PHP类库,用于实现基本的汉化功能。该类库通过定义一个静态方法来获取预设的汉化字符串。同时,文章演示了如何在实际应用中调用该方法,并展示了当请求的键存在与不存在时的不同处理方式。
223

被折叠的 条评论
为什么被折叠?



