Skip to content

Instantly share code, notes, and snippets.

@wotupset
Created November 26, 2013 09:33
Show Gist options
  • Save wotupset/7655679 to your computer and use it in GitHub Desktop.
Save wotupset/7655679 to your computer and use it in GitHub Desktop.
刪掉三字元文字
<?php
header("content-Type: text/html; charset=utf-8"); //語言強制
$str="asd中文ㄍㄍㄍ";
$len = strlen($str);
$cc=0;
for($i = 0; $i < $len; $i++){
$char = substr($str, $i, 1); //函数返回字符串的一部分
if(ord($char) > 127){//非字母
$arr[$cc][0] = substr($str, $i, 3); //前3字元 函数返回字符串的一部分
$arr[$cc][1] = "3";
$i=$i+2;
}else{
$arr[$cc][0] = substr($str, $i, 1); //前1字元 函数返回字符串的一部分
$arr[$cc][1] = "1";
}
$cc=$cc+1;
}
echo "<pre>".print_r($arr)."</pre>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment