PHP 汉字、拼音、unicode、声母、韵母互相转换
汉字 "pinyin" => 拼音 "pinyin_s" => 声母 "pinyin_y" => 韵母 "type" => 声调(1,2,3,4) "unicode" => 汉字unicode * ); */ define('IM_FEIYAN', true); include_once 'config.php'; $data['words'] = null; $data_root = &$data['words']; $word = strtolower(urldecode(Filter::http_get("word"))); if( empty($word) ){ $data_root['result_code'] = 0; $data_root['desc'] = "Parameter Word Can't be Empty"; } else { $page = Filter::http_get("page"); $page = !empty($page) && intval($page)>=1 ? intval($page) : 1; $size = Filter::http_get("size"); $size = !empty($size) && intval($size)>=1 ? intval($size) : 10; $set = ( $page-1 )*$size; //fuzzy:模糊查询 accurate:精确查询 $act = Filter::http_get("act"); $act = in_array($act,array("fuzzy","accurate")) ? $act : "fuzzy"; if( $act == "fuzzy" ) { $sql = "SELECT COUNT(id) FROM words WHERE search_index LIKE '%{$word}%'"; $total = $db->getone($sql); $pages = $total%$size==0 ? intval($total/$size) : intval($total/$size)+1; $sql = "SELECT * FROM words WHERE search_index LIKE '%{$word}%' LIMIT $set,$size"; } elseif ( $act == "accurate" ) { $column = preg_match("/^[a-z]+$/",$word) ? "pinyin" : ( preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$word) ? "word" : "unicode"); $sql = "SELECT COUNT(id) FROM words WHERE $column LIKE '%{$word}%'"; $total = $db->getone($sql); $pages = $total%$size==0 ? intval($total/$size) : intval($total/$size)+1; $sql = "SELECT * FROM words WHERE $column LIKE '%{$word}%' LIMIT $set,$size"; } $res = $db->getall($sql); if( empty($res) ){ $data_root['result_code'] = 1; $data_root['desc'] = 'Data is Empty'; } else { foreach ( $res as &$row ) { $data_root["word"][] = array( "word" => $row["word"], "pinyin" => $row["pinyin"], "pinyin_s" => $row["pinyin_s"], "pinyin_y" => $row["pinyin_y"], "type" => $row["type"], "unicode" => "\"".$row["unicode"]."\"" ); } } } //导出XML或者json output( $data ); ?>
Copy after login
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
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article
What's New in Windows 11 KB5054979 & How to Fix Update Issues
4 weeks ago
By DDD
How to fix KB5055523 fails to install in Windows 11?
3 weeks ago
By DDD
How to fix KB5055518 fails to install in Windows 10?
3 weeks ago
By DDD
Strength Levels for Every Enemy & Monster in R.E.P.O.
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Blue Prince: How To Get To The Basement
3 weeks ago
By DDD

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
Java Tutorial
1653
14


CakePHP Tutorial
1413
52


Laravel Tutorial
1304
25


PHP Tutorial
1251
29


C# Tutorial
1224
24

