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


PHP Uuid::v4方法代码示例

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


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

示例1: applyElementUuids

 /**
  * Adds UUID data attributes to all elements in the document, skipping cdata blocks.
  * @param $html html source
  * @return string
  */
 public function applyElementUuids($html)
 {
     //remove CDATA blocks from source and replace with tokens
     $cdata = array();
     $html = preg_replace_callback('/<!\\[CDATA\\[((?:[^]]|\\](?!\\]>))*)\\]\\]>/', function ($matches) use(&$cdata) {
         $index = count($cdata);
         $replacement = "{{{CDATA-{$index}" . "}}}";
         $cdata[$index] = $matches[0];
         return $replacement;
     }, $html);
     //Add uuid attribute to all tags
     $content = preg_replace_callback("/(<([\\w]+)[^>]*>)/", function ($matches) {
         if (strpos($matches[0], 'data-chaucer-element-id') === false) {
             $id = Uuid::v4();
             $search = '<' . $matches[2];
             $replace = '<' . $matches[2] . ' data-chaucer-element-id="' . $id . '"';
             return str_replace($search, $replace, $matches[0]);
         }
         return $matches[0];
     }, $html);
     //Put CDATA blocks back into source
     if (count($cdata) > 0) {
         for ($x = 0; $x < count($cdata); $x++) {
             $search = "{{{CDATA-{$x}" . "}}}";
             $content = str_replace($search, $cdata[$x], $content);
         }
     }
     return $content;
 }
开发者ID:skypeter1,项目名称:webapps,代码行数:34,代码来源:ImportProcessor.php

示例2: generate

 /**
  * @brief Generates a Universally Unique IDentifier, version 1, 3, 4 or 5.
  *
  * This function generates a truly random UUID. The built in CakePHP String::uuid() function
  * is not cryptographically secure. You should uses this function instead.
  *
  * @see http://tools.ietf.org/html/rfc4122#section-4.4
  * @see http://en.wikipedia.org/wiki/UUID
  * @return string A UUID, made up of 32 hex digits and 4 hyphens.
  */
 function generate($version = null, $ns = null, $name = null)
 {
     if ($version == null) {
         $version = $this->version;
     }
     switch ($version) {
         case Uuid::UUID_V1:
             return Uuid::v1();
         case Uuid::UUID_V3:
             return Uuid::v3($ns, $name);
         case Uuid::UUID_V4:
             return Uuid::v4();
         case Uuid::UUID_V5:
             return Uuid::v5($ns, $name);
     }
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:26,代码来源:uuid.php


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