Home Backend Development PHP Tutorial 拼音码表的生成_PHP

拼音码表的生成_PHP

Jun 01, 2016 pm 12:27 PM
ar lt Pinyin generate

/**
拼音码表的生成:
启动输入法生成器在逆转换选项卡中装入window的拼音输入法并将其保存为文
本文件(winpy.txt)备用。

下面的代码将拼音码表文件(文本)装入到数组$pymb中,结构为:(拼音,(汉字...))
码表转换时间较长,应转换后另行保存
*/
$filename = "pymb.txt";
if(file_exists($filename)) {
$fp = fopen($filename,"r");
$pymb = unserialize(fread($fp,filesize($filename)));
fclose($fp);
}else {
$filename = "winpy.txt";
$fp = fopen($filename,"r");
$old = "";
$ar = array();
$pymb = array();
while(! feof($fp)) {
$buffer = fgets($fp,128);
sscanf($buffer,"%2s%s",$ch,$py);
if($ch >= "啊" && ord($py) $pymb[$ch] = $py;
}
}
fclose($fp);
$fp = fopen("pymb.txt","w");
fwrite($fp,serialize($pymb)."\n");
fclose($fp);
}
?>
应用例,给文字加上拼音


/**
应用例,给文字加上拼音。为简化起见,假定全为中文
*/

function get_py($text) {
global $pymb;
$i = 0;
$n = strlen($text);
$ar = array();
while($i $ch = $text[$i ];
$py = " ";
if(ord($ch) > 128) {
$ch .= $text[$i ];
$py = $pymb[$ch];
}
$ar[] = array($ch,$py);
}
return $ar;
}

$text = " 拼音码表的生成:
启动输入法生成器在逆转换选项卡中装入window的拼音输入法并将其保存为文
本文件(winpy.txt)备用。

下面的代码将拼音码表文件(文本)装入到数组$pymb中,结构为:(拼音,(汉字...))
码表转换时间较长,应转换后另行保存
";


$ar = get_py($text);
//print_r($ar);

echo "

";
for($i=0;$i echo "";
}
echo "";
for($i=0;$i echo "";
}
echo "
".$ar[$i][1]."
".$ar[$i][0]."
";
?>

Statement of this Website
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

XREAL founder Xu Chi: Apple lets everyone see the future of spatial computing, and we work hard to let everyone see the present of spatial computing. XREAL founder Xu Chi: Apple lets everyone see the future of spatial computing, and we work hard to let everyone see the present of spatial computing. Jun 02, 2024 pm 07:55 PM

XREAL launched a new product - XREALBeamPro at the spatial computing new product launch conference, priced from 1,299 yuan. According to the official introduction, XREALBeamPro is a computing terminal that gradually releases 2D applications into 3D space. Equipped with XREALAR glasses, it will form a "complete consumer-grade AR space computing system" and minimize the migration cost of users from the mobile phone side. In terms of design, XREALBeamPro looks like a smartphone, but it is not a mobile phone product, but a spatial computing terminal equipped with a touch display. It is officially positioned as an “AR spatial computing terminal like a Phone”. At the press conference, XREAL founder and CEO Xu Chi expressed his enthusiasm for BeamPro’s capabilities.

How to generate refreshable image verification code using PHP How to generate refreshable image verification code using PHP Sep 13, 2023 am 11:54 AM

How to use PHP to generate refreshable image verification codes. With the development of the Internet, in order to prevent malicious attacks and automatic machine operations, many websites use verification codes for user verification. One common type of verification code is the image verification code, which generates a picture containing random characters and requires the user to enter the correct characters before proceeding. This article will introduce how to use PHP to generate refreshable image verification codes and provide specific code examples. Step 1: Create a verification code image First, we need to create a verification code image

Microsoft explores AR/VR patents using microlens arrays for wide-range chief ray angle manipulation Microsoft explores AR/VR patents using microlens arrays for wide-range chief ray angle manipulation Sep 30, 2023 pm 09:29 PM

(Nweon September 26, 2023) Microsoft believes that MicroLED has the characteristics of small size, light weight, high brightness, and high packaging density, and may be particularly suitable for head-mounted devices that require high resolution, small size, and light weight. monitor. In a patent application titled "Microlenses providing wide range chief ray angle manipulation for panel display", Microsoft introduced a microlens that provides wide range chief ray angle manipulation for panel display, and a display system configured with the microlens array. Wherein, each microlens in the array corresponds to a respective pixel of the panel display. Microlenses are configured according to their

No longer worry about being stopped by your boss for a small meeting before get off work. The AI ​​assistant will help you automatically generate meeting minutes. No longer worry about being stopped by your boss for a small meeting before get off work. The AI ​​assistant will help you automatically generate meeting minutes. Sep 04, 2023 pm 11:21 PM

iFlytek has upgraded the meeting minutes function, which can directly convert spoken expressions into written drafts, and AI can summarize meeting minutes based on recordings. AI can help you complete the writing of meeting minutes. On August 31, the iFlytek web version was upgraded, adding a real-time recording function on the PC side, which can use artificial intelligence to intelligently generate meeting minutes. The launch of this function will greatly improve the efficiency of users in organizing content and following up on key work items after meetings. For people who often attend meetings, this function is undoubtedly a very practical tool that can save a lot of time and energy. The application scenario of this function is mainly to convert recordings on the PC to text and automatically generate meeting minutes, aiming to provide users with the best quality. Products with excellent services and the most advanced technology to quickly improve office efficiency

How to build AR/VR applications using PHP How to build AR/VR applications using PHP Jun 11, 2023 pm 07:22 PM

With the development of AR (Augmented Reality) and VR (Virtual Reality), these two technologies have become an important part of innovation and experience. With the popularity of PHP as a network programming language, PHP has become a feasible choice for developing AR/VR applications. This article will introduce how to use PHP to build AR/VR applications. 1. Understand AR and VR technologies Before we start creating AR/VR applications, we need to understand the different technologies and libraries. AR technology allows virtual objects or information to interact with real-world environments. V

How to do basic natural language generation using PHP How to do basic natural language generation using PHP Jun 22, 2023 am 11:05 AM

Natural language generation is an artificial intelligence technology that converts data into natural language text. In today's big data era, more and more businesses need to visualize or present data to users, and natural language generation is a very effective method. PHP is a very popular server-side scripting language that can be used to develop web applications. This article will briefly introduce how to use PHP for basic natural language generation. Introducing the natural language generation library The function library that comes with PHP does not include the functions required for natural language generation, so

Generate a waffle chart using pyWaffle in Python Generate a waffle chart using pyWaffle in Python Aug 17, 2023 am 11:49 AM

Data visualization is essential for efficient information understanding and presentation. Among the many chart types available, waffle charts are a novel way of displaying data in a grid-like structure with square tiles. The powerful Python module PyWaffle facilitates the development of waffle charts, similar to many computational and data analysis methods. In this article, we will look at how to create a waffle chart using the sophisticated Python module PyWaffle. Let’s install PyWafle and see how to use it to visualize categorical data. Run the following command in your cmd to install the library and then import it into your code. The Chinese translation of pipinstallpywaffleExample1 is: Example 1 In this example, we

Mojie Technology debuted at CES for the first time, leading the AR innovation trend! Mojie Technology debuted at CES for the first time, leading the AR innovation trend! Jan 14, 2024 pm 09:06 PM

From January 9th to 12th, more than 4,000 exhibitors gathered at CES, the consumer electronics "Spring Festival Gala". As an innovative company in the field of consumer AR, Mojie Technology participated in CES for the first time, fully demonstrating the strong strength of Chinese AR companies in core devices, complete machine solutions and customized services. At the Mojie booth, the AR glasses based on binocular resin diffraction light waveguide + MicroLED were displayed, which aroused the interest of many visitors, who tried them on and experienced their functions. This AR glasses has many practical features. First, the wearer can view the text content in real time through the glasses lens, which makes reading more convenient. Secondly, the glasses have built-in microphones that can collect voice information and convert it into text in the specified language through the instant translation function.

See all articles