当前位置: 首页>>代码示例>>PHP>>正文


PHP Strings::chr方法代码示例

本文整理汇总了PHP中Nette\Utils\Strings::chr方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::chr方法的具体用法?PHP Strings::chr怎么用?PHP Strings::chr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\Utils\Strings的用法示例。


在下文中一共展示了Strings::chr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildMOFile

 /**
  * Build gettext MO file
  * @param string $file
  * @param string
  */
 private function buildMOFile($file, $identifier)
 {
     $dictionary = array_filter($this->dictionary, function ($data) use($identifier) {
         return $data['file'] === $identifier;
     });
     ksort($dictionary);
     $metadata = implode("\n", $this->generateMetadata($identifier));
     $items = count($dictionary) + 1;
     $ids = Strings::chr(0x0);
     $strings = $metadata . Strings::chr(0x0);
     $idsOffsets = array(0, 28 + $items * 16);
     $stringsOffsets = array(array(0, strlen($metadata)));
     foreach ($dictionary as $key => $value) {
         $id = $key;
         if (is_array($value['original']) && count($value['original']) > 1) {
             $id .= Strings::chr(0x0) . end($value['original']);
         }
         $string = implode(Strings::chr(0x0), $value['translation']);
         $idsOffsets[] = strlen($id);
         $idsOffsets[] = strlen($ids) + 28 + $items * 16;
         $stringsOffsets[] = array(strlen($strings), strlen($string));
         $ids .= $id . Strings::chr(0x0);
         $strings .= $string . Strings::chr(0x0);
     }
     $valuesOffsets = array();
     foreach ($stringsOffsets as $offset) {
         list($all, $one) = $offset;
         $valuesOffsets[] = $one;
         $valuesOffsets[] = $all + strlen($ids) + 28 + $items * 16;
     }
     $offsets = array_merge($idsOffsets, $valuesOffsets);
     $mo = pack('Iiiiiii', 0x950412de, 0, $items, 28, 28 + $items * 8, 0, 28 + $items * 16);
     foreach ($offsets as $offset) {
         $mo .= pack('i', $offset);
     }
     file_put_contents($file, $mo . $ids . $strings);
 }
开发者ID:salamek,项目名称:gettexttranslator,代码行数:42,代码来源:Gettext.php

示例2: cbString

 private function cbString($m)
 {
     static $mapping = array('t' => "\t", 'n' => "\n", '"' => '"', '\\' => '\\', '/' => '/', '_' => " ");
     $sq = $m[0];
     if (isset($mapping[$sq[1]])) {
         return $mapping[$sq[1]];
     } elseif ($sq[1] === 'u' && strlen($sq) === 6) {
         return Strings::chr(hexdec(substr($sq, 2)));
     } elseif ($sq[1] === 'x' && strlen($sq) === 4) {
         return chr(hexdec(substr($sq, 2)));
     } else {
         $this->error("Invalid escaping sequence {$sq}");
     }
 }
开发者ID:exesek,项目名称:nette20login,代码行数:14,代码来源:Neon.php

示例3: load

	/**
	 * @param string
	 * @return \Nella\Localization\Dictionary
	 * @throws \Nette\InvalidArgumentException
	 */
	public function load($lang, Dictionary $dictionary)
	{
		$path = str_replace(array('%dir%', '%lang%'), array($dictionary->dir, $lang), $this->fileMask);
		if (!file_exists($path)) {
			return;
		}
		if (@filesize($path) < 10) {
			throw new \Nette\InvalidArgumentException("File '$path' is not a gettext file");
		}

		$handle = @fopen($path, "rb");

		$endian = FALSE;
		$read = function($bytes) use ($handle, $endian) {
			$data = fread($handle, 4 * $bytes);
			return $endian === FALSE ? unpack('V'.$bytes, $data) : unpack('N'.$bytes, $data);
		};

		$input = $read(1);
		if (Strings::lower(substr(dechex($input[1]), -8)) == "950412de") {
			$endian = FALSE;
		} elseif (Strings::lower(substr(dechex($input[1]), -8)) == "de120495") {
			$endian = TRUE;
		} else {
			throw new \Nette\InvalidArgumentException("File '$path' is not a gettext file");
		}

		$input = $read(1);

		$input = $read(1);
		$total = $input[1];

		$input = $read(1);
		$originalOffset = $input[1];

		$input = $read(1);
		$translationOffset = $input[1];

		fseek($handle, $originalOffset);
		$orignalTmp = $read(2 * $total);
		fseek($handle, $translationOffset);
		$translationTmp = $read(2 * $total);

		$metadata = array();

		for ($i = 0; $i < $total; ++$i) {
			if ($orignalTmp[$i * 2 + 1] != 0) {
				fseek($handle, $orignalTmp[$i * 2 + 2]);
				$original = @fread($handle, $orignalTmp[$i * 2 + 1]);
			} else {
				$original = "";
			}

			if ($translationTmp[$i * 2 + 1] != 0) {
				fseek($handle, $translationTmp[$i * 2 + 2]);
				$translation = fread($handle, $translationTmp[$i * 2 + 1]);
				if ($original === "") {
					$metadata += $this->decodeMetadata($translation);
					continue;
				}

				$original = explode(Strings::chr(0x00), $original);
				$translation = explode(Strings::chr(0x00), $translation);
				// needed $original data (if array) ?
				$dictionary->addTranslation(is_array($original) ? $original[0] : $original, $translation);
			}
		}

		$dictionary->metadata = $metadata;
		if (isset($metadata['Plural-Forms'])) {
			$dictionary->pluralForm = $metadata['Plural-Forms'];
		}
	}
开发者ID:norbe,项目名称:framework,代码行数:78,代码来源:Gettext.php


注:本文中的Nette\Utils\Strings::chr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。