FeedWriter\Feed::uuid PHP Method

uuid() public static method

The UUID is based on an MD5 hash. If no key is given, a unique ID as the input for the MD5 hash is generated.
Author: Anis uddin Ahmad ([email protected])
public static uuid ( string $key = null, string $prefix = '' ) : string
$key string optional key on which the UUID is generated
$prefix string an optional prefix
return string the formatted UUID
    public static function uuid($key = null, $prefix = '')
    {
        $key = $key == null ? uniqid(rand()) : $key;
        $chars = md5($key);
        $uuid = substr($chars, 0, 8) . '-';
        $uuid .= substr($chars, 8, 4) . '-';
        $uuid .= substr($chars, 12, 4) . '-';
        $uuid .= substr($chars, 16, 4) . '-';
        $uuid .= substr($chars, 20, 12);
        return $prefix . $uuid;
    }

Usage Example

Example #1
0
 /**
  * Make the channels.
  *
  * @access   private
  * @return   string  The feed header as XML containing all the feed metadata.
  */
 private function makeChannels()
 {
     $out = '';
     //Start channel tag
     switch ($this->version) {
         case Feed::RSS2:
             $out .= '<channel>' . PHP_EOL;
             break;
         case Feed::RSS1:
             $out .= isset($this->data['ChannelAbout']) ? "<channel rdf:about=\"{$this->data['ChannelAbout']}\">" : "<channel rdf:about=\"{$this->channels['link']}\">";
             break;
     }
     //Print Items of channel
     foreach ($this->channels as $key => $value) {
         // In ATOM feeds, strip all ATOM namespace prefixes from the tag name. They are not needed here,
         // because the ATOM namespace name is set as default namespace.
         if ($this->version == Feed::ATOM && strncmp($key, 'atom', 4) == 0) {
             $key = substr($key, 5);
         }
         // The channel element can occur multiple times, when the key 'content' is not in the array.
         if (!isset($value['content'])) {
             // If this is the case, iterate through the array with the multiple elements.
             foreach ($value as $singleElement) {
                 $out .= $this->makeNode($key, $singleElement['content'], $singleElement['attributes']);
             }
         } else {
             $out .= $this->makeNode($key, $value['content'], $value['attributes']);
         }
     }
     if ($this->version == Feed::RSS1) {
         //RSS 1.0 have special tag <rdf:Seq> with channel
         $out .= "<items>" . PHP_EOL . "<rdf:Seq>" . PHP_EOL;
         foreach ($this->items as $item) {
             $thisItems = $item->getElements();
             $out .= "<rdf:li resource=\"{$thisItems['link']['content']}\"/>" . PHP_EOL;
         }
         $out .= "</rdf:Seq>" . PHP_EOL . "</items>" . PHP_EOL . "</channel>" . PHP_EOL;
     } else {
         if ($this->version == Feed::ATOM) {
             // ATOM feeds have a unique feed ID. This is generated from the 'link' channel element.
             $out .= $this->makeNode('id', Feed::uuid($this->channels['link']['attributes']['href'], 'urn:uuid:'));
         }
     }
     return $out;
 }
All Usage Examples Of FeedWriter\Feed::uuid