search
Homephp教程php手册PHP将简体汉字转为繁体的方法

近来一项目中涉及到将简体汉字转换为繁体汉字,网上搜了搜,找了半天,发现没个能用的,不过最终也算是对这个过程有所了解了。网上大多数文章提供的思想就是在一个简体,繁体对应的表中查找相对应的汉字,然后进行替换的,原理就是这么简单。

没办法,找不到现成的,就得站在前辈们的肩膀上自己创造了。让我倍感舒服的是找到了一个中文简体,繁体对应的数据表,根据自己的思路将其整理成了一个以简体字为键,繁体字为值的一个一维数组,类似下面这样的一个数组结构:

$data=array('侧'=>'側','厂'=>'廠');

好了,根据这个结构,相应的替换方法如下:

function J2F($str){
	if(trim($str)==''){
		return '';
	}
	$fstr='';
    include 'J2FData.php';//此数据文件下面有下载地址
	$count=mb_strlen($str,'utf-8');
    for($i=0;$i
<p><font face="Courier New">具体用法如下:</font></p>
<pre title="code">
<?php $str='本站是一个php程序员的工作生活笔记,本站包含了php网络编程学习教程,数据库(主要是MySQL和Access数据库)教程,javascript,jquery,div+css,html,windows系统,linux系统以及健康养生方面的学习笔记和生活经验的积累!';
echo J2F($str);

结果将输出如下:

本站是一個php程序員的工作生活筆記,本站包含了php網絡編程學習教程,數據庫(主要是MySQL和Access數據庫)教程,javascript,jquery,div+css,html,windows系統,linux系統以及健康養生方面的學習筆記和生活經驗的積累!

php简体=>繁体数组数据文件下载



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.