コード例 #1
0
ファイル: XmlElement.php プロジェクト: chitanka/sfb-converter
 /**
  * Generate an anchor name for a given string.
  *
  * @param string  $text    A string
  * @param bool    $unique  Always generate a unique name
  *                         (consider all previously generated names)
  */
 public function getAnchorName($text, $unique = true)
 {
     $text = Char::cyr2lat($text);
     $text = strtolower($text);
     $text = strtr($text, array(' ' => '_', '/' => '-', '<br />' => '_'));
     $text = strip_tags($text);
     $text = preg_replace('/[^\\w_-]/', '', $text);
     $text = urlencode(iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $text));
     if ($text === '') {
         $text = '_' . $text;
     }
     if ($unique) {
         if (isset($this->_anchorNames[$text])) {
             $this->_anchorNames[$text]++;
             $text .= '.' . $this->_anchorNames[$text];
         } else {
             $this->_anchorNames[$text] = 1;
         }
     }
     return $text;
 }