首页 > php代码

php获取中文字符拼音首字母实例

实例1

function getFirstCharter($str) {
    if (empty($str)) {return '';}
    $fchar = ord($str{0});
    if ($fchar>=ord('A') && $fchar<=ord('z')) return strtoupper($str{0});
    $s1 = iconv('UTF-8', 'gb2312', $str);
    $s2 = iconv('gb2312', 'UTF-8', $s1);
    $s = $s2 == $str ? $s1 : $str;
    $asc = ord($s{0})*256 + ord($s{1}) - 65536;
    if ($asc>=-20319 && $asc<=-20284) return 'A';
    if ($asc>=-20283 && $asc<=-19776) return 'B';
    if ($asc>=-19775 && $asc<=-19219) return 'C';
    if ($asc>=-19218 && $asc<=-18711) return 'D';
    if ($asc>=-18710 && $asc<=-18527) return 'E';
    if ($asc>=-18526 && $asc<=-18240) return 'F';
    if ($asc>=-18239 && $asc<=-17923) return 'G';
    if ($asc>=-17922 && $asc<=-17418) return 'H';
    if ($asc>=-17417 && $asc<=-16475) return 'J';
    if ($asc>=-16474 && $asc<=-16213) return 'K';
    if ($asc>=-16212 && $asc<=-15641) return 'L';
    if ($asc>=-15640 && $asc<=-15166) return 'M';
    if ($asc>=-15165 && $asc<=-14923) return 'N';
    if ($asc>=-14922 && $asc<=-14915) return 'O';
    if ($asc>=-14914 && $asc<=-14631) return 'P';
    if ($asc>=-14630 && $asc<=-14150) return 'Q';
    if ($asc>=-14149 && $asc<=-14091) return 'R';
    if ($asc>=-14090 && $asc<=-13319) return 'S';
    if ($asc>=-13318 && $asc<=-12839) return 'T';
    if ($asc>=-12838 && $asc<=-12557) return 'W';
    if ($asc>=-12556 && $asc<=-11848) return 'X';
    if ($asc>=-11847 && $asc<=-11056) return 'Y';
    if ($asc>=-11055 && $asc<=-10247) return 'Z';
    return null;

阅读全文

php 异步执行脚本程序代码

在Linux下要让一个脚本挂在后台执行可以在命令的结尾加上一个 "&" 符号,有时候这还不够,需要借助nohup命令,关于nohup,


玩过Linux的人应该都知道,如果想让一个程序在后台运行,只要在执行命令的末尾加上一个&符号就可以了。但是这种方式不是很保险,有些程序当你登出终端后它就会停止。那么如何让一个程序真正永远在后台执行呢。答案就是使用 nohub 命令,格式为:

阅读全文

浅析php中empty与isset区别

empty是判断变量值是非空或非零的值。对应空定义包括:""(空字符串)、0、"0"、NULL、FALSE、array()和$var(只声明但未赋值)。也就是说当变量值为上述这些,empty返回TRUE,其他的都返回FALSE。

阅读全文

php 中file_get_contents超时问题的解决方法

创建一个可以控制的资源句柄,通过控制资源句柄超时来控制file_get_contents这个方法的超时时间,使用起来很方便,也很简单。


$context = stream_context_create(array(
     'http' => array(
      'timeout' => 3000 //超时时间,单位为秒
     )
)); 
// Fetch the URL's contents
$contents = file_get_contents('http://www.phprm.com', 0, $context);

阅读全文