public function get_file_content()
{
// 连接文件并读取内容 dirname(__FILE__): 得到当前文件地址
$contents = file_get_contents(dirname(__FILE__).'/time.php');
// 获取文件编码方式
$encoding = mb_detect_encoding($contents, array('GB2312', 'GBK', 'UTF-16', 'UCS-2', 'UTF-8', 'BIG5', 'ASCII'));
// 修改编码为utf-8 防止乱码
$contents = iconv($encoding, 'UTF-8', $contents);
// 按行分割 返回一维数组
$contents = explode("\n", $contents);
// 组织数据 &符:可直接对$contents赋值
foreach ($contents as &$info)
{
$info= array(
'zone' => $this->get_sub_str('"', '">', $info),
'time_differ' => $this->get_sub_str('(', ')', $info),
'title_en' => $this->get_sub_str(') ', '</option>', $info),
);
}
// 打印查看结果
var_dump($contents);die;
}
// 截取指定两个字符串之间的字符串
private function get_sub_str($start,$end,$str)
{
// 得到要截取字符串的开始位置 mb_strpos(): 得到字符串首次出现的位置
$start = mb_strpos($str,$start) + mb_strlen($start);
// 得到要截取字符串的长度
$length = mb_strpos($str,$end) - $start;
// 截取字符串
return mb_substr($str,$start,$length);
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?