拼音输入的检查

最近搞个东西需要能处理拼音检查功能,不处理英文检查。。

顺便提供一个拼写检查的工具

http://php.freehostingguru.com/group.php-4.php

不过这边要求比较低,只要检查出拼音是否输入错误。

考虑两个问题需要解决。

一:拼音是否强制代入了空格。

二:拼音是否可以不用输入空格。

实现思路

将以下字符串,循环比对,替换。不过需要注意一个东西,长的优先。否则替换会出问题。(自己手动写个正则处理下, 并按长度排序。)

a   ai   an   ang   ao
ba   bai   ban   bang   bao   bei   ben   beng   bi   bia   biao   bie   bin   bing   bo   bu
ca   cai   can   cang   cao   ce   cen   ceng   cha   chai   chan     chang   chao   che   chen   cheng   chi  chong  chou  chu  chua  chuai  chuan  chuang  chui  chun  chuo  ci  cong  cou  cu  cuan  cui  cun  cuo
da  dai  dan  dang  dao  de  dei  den  deng  di  dia  dian  diao  die  ding  diu  dong  dou  du  duan  dui  dun  duo
e  en  eng  er
fa  fan  fang  fei  fen  feng  fiao  fo  fou  fu
ga  gai  gan  gang  gao  ge  gei  gen  geng  gong  gou  gu  gua  guai  guan  guang  gui  gun  guo
ha  hai  han  hang  hao  he  hei  hen  heng  hong  hou  hu  hua  huai  huan  huang  hui  hun  huo
ji  jia  jian  jiang  jiao  jie  jin  jing  jiong  jiu  ju  juan  jue
ka  kai  kan  kang  kao  ke  ken  keng  kong  kou  ku  kua  kuai  kuan  kuang  kui  kun  kuo
la  lai  lan  lang  lao  le  lei  leng  li  lia  lian  liang  liao  lie  lin  ling  liu  lo  long  lou  lu  luan  lun  luo  lv  lve
ma  mai  man  mang  mao  me  mei  men  meng  mi  mian  miao  mie  min  ming  miu  mo  mou  mu
na  nai  nan  nang  nao  ne  nei  nen  neng  ni  nian  niang  niao  nie  nin  ning  niu  nong  nou  nu  nuan  nun  nuo  nv  nve
o  ou
pa  pai  pan  pang  pao  pei  pen  peng  pi  pian  piao  pie  pin  ping  po  pou  pu
qi  qia  qian  qiang  qiao  qie  qin  qing  qiong  qiu  qu  quan  que  qun
ran  rang  rao  re  ren  reng  ri  rong  rou  ru  rua  ruan  rui  run  ruo
sa  sai  san  sang  sao  se  sen  seng  sha  shai  shan  shang  shao  she  shei  shen  sheng  shi  shou  shu  shua  shuai  shuan  shuang  shui  shun  shuo  si  song  sou  su  suan  sui  sun  suo
ta  tai  tan  tang  tao  te  tei  teng  ti  tian  tiao  tie  ting  tong  tou  tu  tuan  tui  tun  tuo
wa  wai  wan  wang  wei  wen  weng  wo  wu
xi  xia  xian  xiang  xiao  xie  xin  xing  xiong  xiu  xu  xuan  xue  xun
ya  yan  yang  yao  ye  yi  yin  ying  yo  yong  you  yu  yuan  yue  yun
za  zai  zan  zang  zao  ze  zei  zen  zeng  zha  zhai  zhan  zhang  zhao  zhe  zhei  zhen  zheng  zhi  zhong  zhou  zhu  zhua  zhuai  zhuan  zhuang  zhui  zhun  zhuo  zi  zong  zou  zu  zuan  zui  zun  zuo

 

 

json dump 支持打印缺损json格式

/**
 * 将utf-8编码串转成原字符串
 * @param string $str utf-8编码
 * @return string 原字符串
 */
function unicode2utf8($str) {
	if (! $str)
		return $str;
	$decode = json_decode ( $str [0] );
	if ($decode)
		return $decode;
	$str = '["' . $str [0] . '"]';
	$decode = json_decode ( $str );
	if (count ( $decode ) == 1) {
		return $decode [0];
	}
	return $str;
}
/**
 * 将json串格式化成串输出,对于有缺损的json串同样可以进行格式化
 * 例:
 * 
 * {
 * "枯asdf":{
 * "adsf":[
 * "hffe顶替标有"
 * ],
 * "0":"asdf"
 * },
 * "0":"hahakao"
 * }
 *
 * @param string $json        	
 * @return void 
 */
function dumpjson($json) {
	$isnojson = json_decode ( $json, true );
	$json = preg_replace_callback ( "/(\uw{4})/", "unicode2utf8", $json );
	$json = preg_replace ( "/\//", '/', $json );
	$data = indent ( $json );
	return "<pre>{$data}</pre>";
}
function indent($json) {
	$result = '';
	$pos = 0;
	$strLen = mb_strlen ( $json, "utf-8" );
	$indentStr = '	';
	$newLine = "n";
	$prevChar = '';
	$outOfQuotes = true;
	for($i = 0; $i <= $strLen; $i ++) {
		// Grab the next character in the string.
		$char = mb_substr ( $json, $i, 1, "utf-8" );
		// Are we inside a quoted string?
		if ($char == '"' && $prevChar != '') {
			$outOfQuotes = ! $outOfQuotes;
			// If this character is the end of an element,
			// output a new line and indent the next line.
		} else if (($char == '}' || $char == ']') && $outOfQuotes) {
			$result .= $newLine;
			$pos --;
			for($j = 0; $j < $pos; $j ++) {
				$result .= $indentStr;
			}
		}
		// Add the character to the result string.
		$result .= $char;
		// If the last character was the beginning of an element,
		// output a new line and indent the next line.
		if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) {
			$result .= $newLine;
			if ($char == '{' || $char == '[') {
				$pos ++;
			}
			for($j = 0; $j < $pos; $j ++) {
				$result .= $indentStr;
			}
		}
		$prevChar = $char;
	}
	$result = preg_replace ( '/\\/', '', $result );
	$result = preg_replace ( '/\"/', '"', $result );
	return $result;
}

 

php 数据调试 by debug_backtrace

/**
 * 返回函数操作链表
 *
 * @param int $level
 *        	返回多少级
 * @param int $start
 *        	跳过原来多少级
 * @param boolean $gettree
 *        	是否按树的形式返回
 * @return array
 */
function backtracelist($level = 3, $start = 0, $gettree = false) {
	$backtrace = debug_backtrace ();
	$btlist = array ();
	if ($backtrace) {
		$level = $level + $start;
		foreach ( $backtrace as $i => $bt ) {
			if ($i < $start) {
				continue;
			}
			if ($i >= $level) {
				break;
			}
			$args = '';
			foreach ( $bt ['args'] as $a ) {
				if (! empty ( $args )) {
					$args .= ', ';
				}
				switch (gettype ( $a )) {
					case 'integer' :
					case 'double' :
						$args .= $a;
						break;
					case 'string' :
						$a = htmlspecialchars ( substr ( $a, 0, 64 ) ) . ((strlen ( $a ) > 64) ? '...' : '');
						$args .= ""$a"";
						break;
					case 'array' :
						$args .= 'Array(' . count ( $a ) . ')';
						break;
					case 'object' :
						$args .= 'Object(' . get_class ( $a ) . ')';
						break;
					case 'resource' :
						$args .= 'Resource(' . strstr ( $a, '#' ) . ')';
						break;
					case 'boolean' :
						$args .= $a ? 'True' : 'False';
						break;
					case 'NULL' :
						$args .= 'Null';
						break;
					default :
						$args .= 'Unknown';
				}
			}
			$params = array (
					"line" => $bt ['line'],
					"file" => $bt ['file'],
					"class" => $bt ['class'],
					"type" => $bt ['type'],
					"function" => $bt ['function'],
					"args" => $args,
					"next" => $params 
			);
			$btitem = array (
					'file' => "{$bt['line']} - {$bt['file']}",
					'call' => "{$bt['class']}{$bt['type']}{$bt['function']}($args)" 
			);
			if ($bt ['args']) {
				$btitem ['args'] = $bt ['args'];
			}
			$btlist [] = $btitem;
		}
	}
	if ($gettree) {
		return $params;
	}
	return $btlist;
}

 

 

/**
 * 通过在 $_GET[GDDEBUG_LEVEL]=1
 * 可以动态调整 gddebug 时 backtracelist 打印出来的层数,方便数据调试
 */
defined ( 'GDDEBUG_LEVEL' ) or define ( 'GDDEBUG_LEVEL', 'GDDEBUG_LEVEL' );

 

/**
 *
 * @author caihaibin
 *         数据打印工具,用来打印各种数据进行调试
 *         字符串为 string(1) "a"
 *         数字为 int(1)
 *         NULL 为 NULL
 *         数组为 Array(
 *         'a'=>'test'
 *         )
 *         对像为 Object xxxx
 *        
 *         另补充数据 debug_backtrace 层级调试,可以方便跟踪数据所在位置 ,具体看 backtracelist()
 *         可以通过 $_GET [GDDEBUG_LEVEL] 指定对应显示层级
 *         再将返回结果插入数据库,可以通过数据库进行数据调试
 */
function gddebug() {
	echo "rn<pre>";
	if (isset ( $_GET [GDDEBUG_LEVEL] )) {
		$level = $_GET [GDDEBUG_LEVEL];
	} else {
		$level = 0;
	}
	$btlist = backtracelist ( $level, 1 );
	if (! empty ( $btlist )) {
		echo "backtracelist:rn";
		foreach ( $btlist as &$btitem ) {
			if (isset ( $btitem ['args'] ))
				$btitem ['args'] = preg_replace ( '/n/ms', "n            ", print_r ( $btitem ['args'], true ) );
		}
		echo htmlspecialchars ( print_r ( $btlist, true ) ) . "rn";
	}
	$arrays = func_get_args ();
	echo "args:rn";
	foreach ( $arrays as $value ) {
		if (is_array ( $value ) || is_object ( $value )) {
			echo htmlspecialchars ( print_r ( $value, true ) ) . "rn";
		} elseif (is_string ( $value )) {
			echo "string(" . strlen ( $value ) . ") "" . htmlspecialchars ( $value ) . ""rn";
		} else {
			var_dump ( $value );
		}
	}
	echo "</pre>";
}

 

微信实现视频在线播放

pc端可用在线直播方式 mms

安卓端可用 rtsp 协议.

但是微信页面,即htm5 video 不支持上述协议。即使开启flash(微信内置浏览器不支持flash,在uc下测试)。本身也无效。调整。

苹果ios类支持自己实现的HLS协议,即后缀为 m3u8 协议的格式,具体实现原理看。

http://blog.csdn.net/andy1219111/article/details/8863506

 

后经测试,发现本身android 4.0以上版本就可以支持HLS ,

具体兼容支持图表看。

http://www.jwplayer.com/html5/hls/

 

尝试正常,除个别手机如三星 s4 这类播放时,由于可以高度识别问题。导致屏幕只有宽度,没高度,播放正常等问题。直接设置高度比即可。

微信测试结果。正常。因为微信的内置浏览器新版本基本上相同,主要是浏览器的内置限制。所以本身不用太担心兼容的问题。或者说,只要新版本测试基本上不用担心一些奇怪的限制,虽然微信的限制本身就比较奇怪。

举例,版本以5.3为准:

视频播放。加载时可以触发播放,本身开启属性autoplay也是可以的,但是通过按钮事件触发的全屏可以触发,但是直接js触发又不行。会报dom exception 11的异常。

结:

目前主要的测试平台为android和iphone。因为本身ios支持的,只测试一个就不用担心了,android各有差异,但是暂时没有发现哪部手机不可播放。

 

补充一个比较有意思的实现,仅供参考:

http://blog.segmentfault.com/xingrz/1190000000392586?page=1#c-1190000000392586-1050000000393206