Home Backend Development PHP Tutorial 给文字加上拼音_PHP

给文字加上拼音_PHP

Jun 01, 2016 pm 12:36 PM
echo Old py Pinyin letter

/**
  拼音码表的生成:
      启动输入法生成器在逆转换选项卡中装入window的拼音输入法并将其保存为文
  本文件(winpy.txt)备用。
  
  下面的代码将拼音码表文件(文本)装入到数组$pymb中,结构为:(拼音,(汉字...))
  码表转换时间较长,应转换后另行保存
*/
$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)     if($py != $old) {
      if($old != "") {
        $pymb[] = array(py => $old,hz => $ar);
      }
      $old = $py;
      $ar = array();
    }
    $ar[] = $ch;
  }
}
fclose($fp);
?>
  应用例,给文字加上拼音


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

$text = "应用例,给文字加上拼音";
echo "

";
for($i=0;$i   $ch = substr($text,$i,2);
  $k = " ";
  for($p=0;$p     if(in_array($ch,$pymb[$p][hz])) {
      $k = $pymb[$p][py];
      break;
    }
  }
  echo "";
}
echo "";
for($i=0;$i   $ch = substr($text,$i,2);
  echo "";
}
echo "
$k
$ch
";
?>
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 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 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)

How to make round pictures and text in ppt How to make round pictures and text in ppt Mar 26, 2024 am 10:23 AM

First, draw a circle in PPT, then insert a text box and enter text content. Finally, set the fill and outline of the text box to None to complete the production of circular pictures and text.

How to add dots to text in word? How to add dots to text in word? Mar 19, 2024 pm 08:04 PM

When we create Word documents on a daily basis, we sometimes need to add dots under certain words in the document, especially when there are test questions. To highlight this part of the content, the editor will share with you the tips on how to add dots to text in Word. I hope it can help you. 1. Open a blank word document. 2. For example, add dots under the words "How to add dots to text". 3. We first select the words "How to add dots to text" with the left mouse button. Note that if you want to add dots to that word in the future, you must first use the left button of the mouse to select which word. Today we are adding dots to these words, so we have chosen several words. Select these words, right-click, and click Font in the pop-up function box. 4. Then something like this will appear

Golang Image Processing: Learn How to Add Watermarks and Text Golang Image Processing: Learn How to Add Watermarks and Text Aug 17, 2023 am 08:41 AM

Golang Image Processing: Learn How to Add Watermarks and Text Quotes: In the modern era of digitalization and social media, image processing has become an important skill. Whether for personal use or business operations, adding watermarks and text are common needs. In this article, we will explore how to use Golang for image processing and learn how to add watermarks and text. Background: Golang is an open source programming language known for its concise syntax, efficient performance and powerful concurrency capabilities. it has become the subject of many developments

How to modify text on pictures How to modify text on pictures Aug 29, 2023 am 10:29 AM

Modifying the text on the image can be done by using image editing software, online tools or screenshot tools. The specific steps are: 1. Open the picture editing software and import the picture that needs to be modified; 2. Select the text tool; 3. Click the text area on the picture to create a text box; 4. Enter the text you want in the text box. 5. If you just want to delete the text on the picture, you can use the eraser tool or the selection tool to select and delete the text area.

How to solve the problem of unable to enter the correct pinyin letters in Ubuntu system How to solve the problem of unable to enter the correct pinyin letters in Ubuntu system Jan 04, 2024 pm 11:10 PM

You cannot type correctly using the Pinyin input method in the Ubuntu system. The words displayed on the input method are not related to the words you want to type. You cannot type the Chinese characters you want to input. This phenomenon often occurs after upgrading the Ubuntu system. How do we solve this problem? The editor below will bring you a solution to the problem that Pinyin cannot be typed correctly in Ubuntu system. Let’s go and see it together! The method is as follows: 1. Press "Ctrl" + "Alt" + "T" on the desktop to open the system terminal: 2. Enter ibus-daemon-drx in the terminal and press Enter: ibus-daemon-drx and then enter pinyin

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

In today's era of rapid technological development, programming languages ​​are springing up like mushrooms after a rain. One of the languages ​​that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

Detailed method for setting up PPT slides by moving the mouse to text to display pictures Detailed method for setting up PPT slides by moving the mouse to text to display pictures Mar 26, 2024 pm 03:40 PM

1. First set a custom animation for the picture object. 2. If you want to make the effect more realistic, please use the animation effect [Appear] as shown above. After setting the custom effect for the picture object, we will see the name of the custom animation on the right side of the window, such as [1good] in the picture. Now use the left button of the mouse to click on the small triangle facing downwards in the direction of the picture, and a pop-up will appear as follows Figure menu list. 3. In the menu shown above, select [Effect Options], and a pop-up will appear as shown in the picture. 4. In the picture above, switch to the [Timing] tab, click [Trigger], then select [Start the effect when the following objects are clicked] below, and select [Title 1: Picture 1] on the right. This setting means that when playing the slideshow, click on the text in [Picture 1], and it will

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

See all articles