convertTo.

@param string $str
@param string $variant
@return string
766931
public function convertTo($str, $variant = 'zh-TW')
    {
        $variant = strtolower($variant);
        $arrayObject = isset($this->table[$variant]) === true ? $this->table[$variant] : $this->table[$this->default];
        $data = $arrayObject->getArrayCopy();

        return strtr($str, $data);
    }
626318
public function toString($str = '')
    {
        $str .= "<{$this->name} xmlns='{$this->ns}' ";
        foreach ($this->attrs as $key => $value) {
            if ($key !== 'xmlns') {
                $value = htmlspecialchars($value);
                $str .= "$key='$value' ";
            }
        }
        $str .= ">";
        foreach ($this->subs as $sub) {
            $str .= $sub->toString();
        }
        $body = htmlspecialchars($this->data);
        $str .= "$body</{$this->name}>";
        return $str;
    }
523464
public static function toVariable($str)
  {
    // Remove dashes and underscores, then convert to camel case.
    $str = self::toSpaceSeparated($str);
    $str = self::toCamelCase($str);

    // Remove leading digits.
    $str = preg_replace('#^[0-9]+.*$#', '', $str);

    // Lowercase the first character.
    $first = substr($str, 0, 1);
    $first = mb_strtolower($first);

    // Replace the first character with the lowercase character.
    $str = substr_replace($str, $first, 0, 1);

    return $str;
  }
80405
public static function toUTF8($str)
    {
        if (!is_null($str) && false === mb_detect_encoding($str, 'UTF-8', true)) {
            $str = utf8_encode($str);
        }

        return $str;
    }
269192
public function wrap($str, $wrap)
    {
        return (is_string($str) && $str !== '') ? $wrap.$str.$wrap : $str;
    }
358362
public static function convertStringToXMLValue(string $str) : string
    {
        $str = str_replace("&amp;", "§", $str);
        $str = str_replace("&", "§", $str);
        $str = str_replace("§", "&amp;", $str);
        $str = str_replace("<", "&lt;", $str);
        $str = str_replace(">", "&gt;", $str);
        $str = str_replace("'", "&apos;", $str);
        $str = str_replace("\"", "&quot;", $str);

        return $str;
    }
773332
public static function decode(String $str) : String
    {
        return str_replace(array_values(self::$phpTagChars), array_keys(self::$phpTagChars), $str);
    }
918575
public static function sanitizeJsVarName($str)
    {
        $out = preg_replace("/ /", '_', trim($str));
        $out = preg_replace("/[^A-Za-z_]/", '', $out);

        return $out;
    }
144488
public static function convertNodeStr($str): string
    {
        $str = \trim($str, '-');

        // convert 'first-second' to 'firstSecond'
        if (\strpos($str, '-')) {
            $str = (string)\preg_replace_callback('/-+([a-z])/', function ($c) {
                return \strtoupper($c[1]);
            }, \trim($str, '- '));
        }

        return $str;
    }
484968
static public function camelcasedToDashed($str) {
        $str = lcfirst($str);
        return preg_replace_callback(
            '/([A-Z])/',
            function ($str) {
                return "-" . strtolower($str[1]);
            },
            $str
        );
    }
82265
private function _strtoupper($str)
    {
        $str = html_entity_decode($str, ENT_COMPAT);

        if (function_exists('mb_strtoupper')) {
            $str = mb_strtoupper($str, 'UTF-8');
        } else {
            $str = strtoupper($str);
        }

        $str = htmlspecialchars($str, ENT_COMPAT);

        return $str;
    }
1063691
public static function convertEncoding($str, $from, $to)
	{
	    if(function_exists('iconv')) {
	        return iconv($from, $to . '//ignore', $str);
	    } elseif(function_exists('mb_convert_encoding')) {
	        return mb_convert_encoding($str, $to, $from);
	    }

	    throw new \Exception('请先安装PHP iconv或mb_string扩展');
	}
1137365
public static function convertXMLValueToString(string $str) : string
    {
        $str = str_replace("&amp;", "&", $str);
        $str = str_replace("&lt;", "<", $str);
        $str = str_replace("&gt;", ">", $str);
        $str = str_replace("&apos;", "'", $str);
        $str = str_replace("&quot;", "\"", $str);

        return $str;
    }
1140457
protected function _replaceTranslate($str) {
		// [__]Text to translate[/__]
		if (preg_match_all('/\[__\](.*?)\[\/__\]/i', $str, $matches)) {
			foreach ($matches[0] as $i => $find) {
				$str = str_replace($find, I18n::translate($matches[1][$i]), $str);
			}
		}

		// [__d|domain]Text to translate[/__d]
		if (preg_match_all('/\[__d\|(.+?)\](.*?)\[\/__d\]/i', $str, $matches)) {
			foreach ($matches[0] as $i => $find) {
				$str = str_replace($find, I18n::translate($matches[2][$i], null, $matches[1][$i]), $str);
			}
		}

		// [__c|category]Text to translate[/__c]
		if (preg_match_all('/\[__c\|(.+?)\](.*?)\[\/__c\]/i', $str, $matches)) {
			foreach ($matches[0] as $i => $find) {
				$str = str_replace($find, I18n::translate($matches[2][$i], null, null, $matches[1][$i]), $str);
			}
		}

		return $str;
	}
835641
static public function fromCamel($str) {
      $str[0] = strtolower($str[0]);
      return preg_replace_callback('/([A-Z])/', function($char) {return "_" . strtolower($char[1]);}, $str);
  }
722307
public static function convertStringToArray($str, $seperator = ',', $limit = PHP_INT_MAX)
    {
        return self::removeEmptyItems(explode($seperator, $str, $limit), function ($param) {
            return self::trimQuots($param);
        });
    }
285666
private function toCamelCase($str)
    {
        // Split string in words.
        $words = preg_split('/[-_]/', strtolower($str)); //explode('_', strtolower($str));

        $return = '';
        foreach ($words as $word) {
            $return .= ucfirst(trim($word));
        }

        return $return;
    }