取得无序随机字符串

@param int $len
@param bool $easyRead = false 是否是人眼容易识别的
@return int
765793
public static function randStr($len, $easyRead = false) {
		if ($easyRead) {
		    $str = 'ab23456789abcdefghzykxmnwpqrstuvwxyz'; // 人眼容易识别的字母数字
		} else {
			$str = '0123456789abcdefghijklmnopqrstuvwxyz';
		}

		$r = '';
		for ($i = 0; $i < $len; $i++) {
			$r .= $str[mt_rand(0, 35)];
		}

		return $r;
	}
553465
function generateCode($len)
  {
    $code = '';

    for($i = 1, $cslen = strlen($this->charset); $i <= $len; ++$i) {
      $code .= strtoupper( $this->charset{rand(0, $cslen - 1)} );
    }
    return $code;
  }
499984
public function isSurroundedByAlnum($pos, $len)
	{
		return ($pos > 0 && $this->isAlnum($this->text[$pos - 1]) && $this->isAlnum($this->text[$pos + $len]));
	}
876255
public static function length($len, $str, $compare = null)
    {
        $actualLen = strlen($str);
        switch ($compare) {
            case 'lte':
            case '<=':
                return $actualLen <= $len;
            case 'gte':
            case '>=':
                return $actualLen >= $len;
            case 'lt':
            case '<':
                return $actualLen < $len;
            case 'gt':
            case '>':
                return $actualLen > $len;
            default:
                return $actualLen == $len;
        }
    }
768236
public function read($len = null)
    {
        if (!class_exists('DomDocument')) {
            throw new BuildException("Could not find the DomDocument class. Make sure PHP has been compiled/configured to support DOM XML.");
        }

        if ($this->processed === true) {
            return -1; // EOF
        }

        // Read XML
        $_xml = null;
        while (($data = $this->in->read($len)) !== -1) {
            $_xml .= $data;
        }

        if ($_xml === null) { // EOF?

            return -1;
        }

        if (empty($_xml)) {
            $this->log("XML file is empty!", Project::MSG_WARN);

            return '';
        }

        $this->log("Transforming XML " . $this->in->getResource() . " using Xinclude ", Project::MSG_VERBOSE);

        $out = '';
        try {
            $out = $this->process($_xml);
            $this->processed = true;
        } catch (IOException $e) {
            throw new BuildException($e);
        }

        return $out;
    }
952036
public static int len(String list, char delimiter, boolean ignoreEmpty) {
	int len = StringUtil.length(list);
	if (len == 0) return 0;

	int count = 0;
	int last = 0;

	for (int i = 0; i < len; i++) {
	    if (list.charAt(i) == delimiter) {
		if (!ignoreEmpty || last < i) count++;
		last = i + 1;
	    }
	}
	if (!ignoreEmpty || last < len) count++;
	return count;
    }
577824
public synchronized int read(byte b[], int off, int len) throws IOException
    {
        int avail=_avail-_pos;
        if (avail <=0)
        {
            fill();
            avail=_avail-_pos;
        }

        if (avail <=0)
            len=-1;
        else
        {
            len=(avail < len) ? avail : len;
            System.arraycopy(_buf,_pos,b,off,len);
            _pos +=len;
        }
        
        return len;
    }
269664
public int read(byte[] b, int off, int len) throws IOException {

    if (currentOffset >= dataLength) {
      return -1;
    }
    
    return doRead(b,off,len);
  }
199364
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->_initialize();
            $this->setInitialized(true);
        }

        $ch = -1;

        if ($this->queuedData !== null && $this->queuedData === '') {
            $this->queuedData = null;
        }

        if ($this->queuedData !== null) {
            $ch = $this->queuedData[0];
            $this->queuedData = substr($this->queuedData, 1);
            if ($this->queuedData === '') {
                $this->queuedData = null;
            }
        } else {
            $this->queuedData = $this->readLine();
            if ($this->queuedData === null) {
                $ch = -1;
            } else {
                if ($this->suffix !== null) {
                    $lf = '';
                    if (StringHelper::endsWith($this->queuedData, "\r\n")) {
                        $lf = "\r\n";
                    } elseif (StringHelper::endsWith($this->queuedData, "\n")) {
                        $lf = "\n";
                    }
                    $this->queuedData = substr($this->queuedData, 0, strlen($this->queuedData) - strlen($lf)) . $this->suffix . $lf;
                }
                return $this->read();
            }
        }
        return $ch;
    }
467863
public function readInt()
    {
        $str = $this->_fread(4);

        return  ord($str[0]) << 24 |
                ord($str[1]) << 16 |
                ord($str[2]) << 8  |
                ord($str[3]);
    }
310732
protected int readFully(InputStream in, byte buffer[], int offset, int len)
        throws java.io.IOException {
        for (int i = 0; i < len; i++) {
            int q = in.read();
            if (q == -1)
                return ((i == 0) ? -1 : i);
            buffer[i+offset] = (byte)q;
        }
        return len;
    }
100775
public static int readLen(byte[] data) {
        if (data.length < Datagram.HEADER_LEN) {
            log.warn("要读取长度的数据报报头不完整");
            return -1;
        } else {
            return convert(data, Datagram.LEN_OFFSET);
        }
    }
504658
public static boolean isNumber(final String text, final int start, final int len){
        for(int i=start; i<start+len; i++){
            char c = text.charAt(i);
            if(!isNumber(c)){
                return false;
            }
        }
        //指定的字符串已经识别为数字串
        //下面要判断数字串是否完整
        if(start>0){
            //判断前一个字符，如果为数字字符则识别失败
            char c = text.charAt(start-1);
            if(isNumber(c)){
                return false;
            }
        }
        if(start+len < text.length()){
            //判断后一个字符，如果为数字字符则识别失败
            char c = text.charAt(start+len);
            if(isNumber(c)){
                return false;
            }
        }
        if(LOGGER.isDebugEnabled()) {
            LOGGER.debug("识别出数字：" + text.substring(start, start + len));
        }
        return true;
    }
968919
public function read($len) {
        // Do a non-blocking read to clear any buffering, even though
        // the code doesn't use the results
        if (is_resource($this->socket_)) {
            @fread($this->socket_, max($len, 8192));
        }

        // Return data from the hard-coded response buffer
        $part = substr($this->respBuffer_, 0, $len);
        $this->respBuffer_ = substr($this->respBuffer_, $len);
        return $part;
    }
51251
protected function unSerializeHandler($data, $keys = [], $len = 0)
    {
        // 如果值是null，直接返回false
        if (null === $data) {
            return false;
        }

        if ('OK' === $data) {
            return $data;
        }

        try {
            //mget
            if (!empty($keys) && is_array($data)) {
                $ret = [];
                array_walk($data, function ($val, $k) use ($keys, $len, &$ret) {
                    if (!is_null($val)) {
                        $key = substr($keys[$k], $len);
                        $val = $this->realUnserialize($val);
                        $ret[$key] = $val;
                    }
                });

                $data = $ret;
            } elseif (is_array($data) && empty($keys)) {
                //eval sRandMember...
                $ret = [];
                array_walk($data, function ($val, $k) use (&$ret) {
                    if (is_array($val)) {
                        foreach ($val as $i => $v) {
                            $val[$i] = $this->realUnserialize($v);
                        }
                    } else {
                        $val = $this->realUnserialize($val);
                    }

                    $ret[$k] = $val;
                });

                $data = $ret;
            } else {
                //get
                $data = $this->realUnserialize($data);
            }
        } catch (\Exception $exception) {
            // do noting
        }

        return $data;
    }
899169
public synchronized int read(byte[] externalBuf, int off, int len) throws IOException {

    if (len == 0) {
      return 0;
    }

    int totalReads = 0;
    while (true) {

      //read
      if (end - pos <= 0) {
        if (len - totalReads >= buf.length) {
          //buffer length is less than asked byte and buffer is empty
          // => filling directly into external buffer
          int reads = super.read(externalBuf, off + totalReads, len - totalReads);
          if (reads <= 0) {
            return (totalReads == 0) ? -1 : totalReads;
          }
          return totalReads + reads;

        } else {

          //filling internal buffer
          fillBuffer(len - totalReads);
          if (end <= 0) {
            return (totalReads == 0) ? -1 : totalReads;
          }
        }
      }

      //copy internal value to buffer.
      int copyLength = Math.min(len - totalReads, end - pos);
      System.arraycopy(buf, pos, externalBuf, off + totalReads, copyLength);
      pos += copyLength;
      totalReads += copyLength;

      if (totalReads >= len || super.available() <= 0) {
        return totalReads;
      }
    }
  }
93270
public static function gbkTruncate($src, $len) {
        $src = strval($src);
        $dest = '';
        $dest_len = 0;
        $src_len = strlen($src);
        for ($i=0;$i<$src_len && $dest_len < $len ; $i++) {
            $ascii = ord($src[$i]);
            
            //单字节部分
            if($ascii < 0x7F)		{
                //控制字符特殊处理
                if(ctype_cntrl($src[$i]) )	{
                    //保留制表符跟回车符
                    if($ascii==0x09 || $ascii==0x0A) {
                        $dest .= $src[$i];
                        $dest_len += 0.5;
                    }
                    //丢掉其它控制字符
                }
                //其它的补充上
                else			{
                    $dest .= $src[$i];
                    $dest_len += 0.5;
                }
            }
            //多字节部分,合法的第一个
            elseif ($ascii >= 0x81 && $ascii<=0xFE)		{
                //丢掉最后半个汉字
                if (1 == ($src_len-$i))			{
                    break;
                }
                //检查第二个字节
                //0x40 - 0xFE
                $b2 = ord($src[++$i]);
                if($b2 >= 0x40 && $b2 <= 0xFE)			{
                    //最后半个
                    if ($dest_len+.5==$len) {
                        break;
                    }
                    $dest .= $src[$i-1] . $src[$i];
                    $dest_len += 1 ;
                }
                //不是gbk范围去掉
            }
            //不是gbk范围去掉
        }
        return $dest;
    }