目录
PHP汉字转拼音代码分析
php
首先需要前台模版index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>汉子转拼音带音标_PHP博客</title> <meta name="keywords" content="php实例,PHP实例教程,php源码,PHP汉字转拼音" /> <meta name="description" content="下面我们讲解一下如何使用PHP来将汉字换转为拼音【带音标】" /> <link rel="stylesheet" type="text/css" href="/Themes/Admin/Public/css/common.css" /> <style> .demo{width:520px; margin:40px auto 0 auto; min-height:250px;} .input{padding:3px; line-height:22px; border:1px solid #ccc} .btn{overflow: hidden;display:inline-block;*display:inline;padding:4px 20px 4px;font-size:14px;line-height:18px;*line-height:20px;color:#fff;text-align:center;vertical-align:middle;cursor:pointer;background-color:#5bb75b;border:1px solid #cccccc;border-color:#e6e6e6 #e6e6e6 #bfbfbf;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px; margin-left:2px} #result{margin-top:20px; line-height:26px; word-break:break-all} .blue{ color: #blue;} .red{ color: #red;} </style> </head> <body> <div class="head"> <div class="head_inner clearfix"> <ul id="nav"> <li><a href="http://liqingbo.cn/">首 页</a></li> <li><a href="http://liqingbo.cn/category/">文章列表</a></li> </ul> <a class="logo" href="http://liqingbo.cn/" title="李清波博客"><img src="/static/imghw/default1.png" data-src="/Public/images/logo.png" class="lazy" alt="李清波博客" style="max-width:90%" /></a> </div> </div> <div class="container"> <div class="demo"> <h2 id="a-nbsp-href-教程-汉子转拼音代码分析-a"><a href="">教程:汉子转拼音代码分析</a></h2> <div>内容:<textarea id="str" class="input" style="width:100%; height:80px"></textarea></div> <div class="input-text"> <input type="button" value="汉->拼" class="btn" id="pinyin"/> </div> <div id="result" class="result"></div> </div> </div> <div class="foot"> Powered by sucaihuo.com 本站皆为作者原创,转载请注明原文链接:<a href="http://liqingbo.cn/" target="_blank">liqingbo.cn</a> </div> <script type="text/javascript" src="/Themes/Admin/Public/js/jquery.js"></script> <script type="text/javascript"> $(function() { $("#pinyin").click(function() { post('pinyin');//加密 }); $("#hanzi").click(function() { post('hanzi');//解密 }); $("#empty").click(function(){ $("#str").val(''); $("#key").val(''); $("#result").text(''); }) }); function post(act) { var str = $("#str").val(); $.post("/admin.php/article/pinyin/?act=" + act, {str: str}, function(data) { $("#result").html(data); }); } </script> </body> </html>
登录后复制
当我们输入所要转换的汉字后,将数据提交到pinyin.php文件进行转换,在返回到index.html文件中
完整代码:
public function pinyin(){ if(IS_POST){ header("Content-Type:text/html;charset=utf-8"); include(APPLICATION."Common/ChinesePinyin.class.php"); $Pinyin = new ChinesePinyin(); $str = $_POST['str']; if(strlen($str)<=0){ echo '请输入要转换的内容'; exit; } $pinyin1 = $Pinyin->TransformWithTone($str); $pinyin2 = $Pinyin->TransformWithoutTone($str); $pinyin3 = $Pinyin->TransformUcwordsOnlyChar($str); $pinyin4 = $Pinyin->TransformUcwords($str); echo '带声调的汉语拼音: <span class="red">'.$pinyin1.'</span>'; echo '<br>'; echo '无声调的汉语拼音: <span class="red">'.$pinyin2.'</span>'; echo '<br>'; echo '首字母只包括汉字: <span class="red">'.$pinyin3.'</span>'; echo '<br>'; echo '首字母和其他字符: <span class="red">'.$pinyin4.'</span>'; echo '<br>'; exit; } $this->display('pinyin'); }
登录后复制
以上例子为thinkphp框架下的
实例效果:汉子转拼音带音标
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前
By 尊渡假赌尊渡假赌尊渡假赌
击败分裂小说需要多长时间?
1 个月前
By DDD
R.E.P.O.最佳图形设置
2 周前
By 尊渡假赌尊渡假赌尊渡假赌
刺客信条阴影:贝壳谜语解决方案
1 周前
By DDD
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前
By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4

CakePHP 是 PHP 的开源框架。它的目的是使应用程序的开发、部署和维护变得更加容易。 CakePHP 基于类似 MVC 的架构,功能强大且易于掌握。模型、视图和控制器 gu
