Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace yii\helpers; use Yii; class BaseStringHelper { public static function byt..

Decoded Output download

<?php
 namespace yii\helpers; use Yii; class BaseStringHelper { public static function byteLength($string) { return mb_strlen((string) $string, "8bit"); } public static function byteSubstr($string, $start, $length = null) { if ($length === null) { $length = static::byteLength($string); } return mb_substr((string) $string, $start, $length, "8bit"); } public static function basename($path, $suffix = '') { $path = (string) $path; $len = mb_strlen($suffix); if ($len > 0 && mb_substr($path, -$len) === $suffix) { $path = mb_substr($path, 0, -$len); } $path = rtrim(str_replace("\", "/", $path), "/"); $pos = mb_strrpos($path, "/"); if ($pos !== false) { return mb_substr($path, $pos + 1); } return $path; } public static function dirname($path) { $normalizedPath = rtrim(str_replace("\", "/", (string) $path), "/"); $separatorPosition = mb_strrpos($normalizedPath, "/"); if ($separatorPosition !== false) { return mb_substr($path, 0, $separatorPosition); } return ''; } public static function truncate($string, $length, $suffix = "...", $encoding = null, $asHtml = false) { $string = (string) $string; if ($encoding === null) { $encoding = Yii::$app ? Yii::$app->charset : "UTF-8"; } if ($asHtml) { return static::truncateHtml($string, $length, $suffix, $encoding); } if (mb_strlen($string, $encoding) > $length) { return rtrim(mb_substr($string, 0, $length, $encoding)) . $suffix; } return $string; } public static function truncateWords($string, $count, $suffix = "...", $asHtml = false) { if ($asHtml) { return static::truncateHtml($string, $count, $suffix); } $words = preg_split("/(\s+)/u", trim($string), 0, PREG_SPLIT_DELIM_CAPTURE); if (count($words) / 2 > $count) { return implode('', array_slice($words, 0, $count * 2 - 1)) . $suffix; } return $string; } protected static function truncateHtml($string, $count, $suffix, $encoding = false) { $config = \HTMLPurifier_Config::create(null); if (Yii::$app !== null) { $config->set("Cache.SerializerPath", Yii::$app->getRuntimePath()); } $lexer = \HTMLPurifier_Lexer::create($config); $tokens = $lexer->tokenizeHTML($string, $config, new \HTMLPurifier_Context()); $openTokens = array(); $totalCount = 0; $depth = 0; $truncated = array(); foreach ($tokens as $token) { if ($token instanceof \HTMLPurifier_Token_Start) { $openTokens[$depth] = $token->name; $truncated[] = $token; ++$depth; } elseif ($token instanceof \HTMLPurifier_Token_Text && $totalCount <= $count) { if (false === $encoding) { preg_match("/^(\s*)/um", $token->data, $prefixSpace) ?: ($prefixSpace = array('', '')); $token->data = $prefixSpace[1] . self::truncateWords(ltrim($token->data), $count - $totalCount, ''); $currentCount = self::countWords($token->data); } else { $token->data = self::truncate($token->data, $count - $totalCount, '', $encoding); $currentCount = mb_strlen($token->data, $encoding); } $totalCount += $currentCount; $truncated[] = $token; } elseif ($token instanceof \HTMLPurifier_Token_End) { if ($token->name === $openTokens[$depth - 1]) { --$depth; unset($openTokens[$depth]); $truncated[] = $token; } } elseif ($token instanceof \HTMLPurifier_Token_Empty) { $truncated[] = $token; } if ($totalCount >= $count) { if (0 < count($openTokens)) { krsort($openTokens); foreach ($openTokens as $name) { $truncated[] = new \HTMLPurifier_Token_End($name); } } break; } } $context = new \HTMLPurifier_Context(); $generator = new \HTMLPurifier_Generator($config, $context); return $generator->generateFromTokens($truncated) . ($totalCount >= $count ? $suffix : ''); } public static function startsWith($string, $with, $caseSensitive = true) { $string = (string) $string; $with = (string) $with; if (!($bytes = static::byteLength($with))) { return true; } if ($caseSensitive) { return strncmp($string, $with, $bytes) === 0; } $encoding = Yii::$app ? Yii::$app->charset : "UTF-8"; $string = static::byteSubstr($string, 0, $bytes); return mb_strtolower($string, $encoding) === mb_strtolower($with, $encoding); } public static function endsWith($string, $with, $caseSensitive = true) { $string = (string) $string; $with = (string) $with; if (!($bytes = static::byteLength($with))) { return true; } if ($caseSensitive) { if (static::byteLength($string) < $bytes) { return false; } return substr_compare($string, $with, -$bytes, $bytes) === 0; } $encoding = Yii::$app ? Yii::$app->charset : "UTF-8"; $string = static::byteSubstr($string, -$bytes); return mb_strtolower($string, $encoding) === mb_strtolower($with, $encoding); } public static function explode($string, $delimiter = ",", $trim = true, $skipEmpty = false) { $result = explode($delimiter, $string); if ($trim !== false) { if ($trim === true) { $trim = "trim"; } elseif (!is_callable($trim)) { $trim = function ($v) use($trim) { return trim($v, $trim); }; } $result = array_map($trim, $result); } if ($skipEmpty) { $result = array_values(array_filter($result, function ($value) { return $value !== ''; })); } return $result; } public static function countWords($string) { return count(preg_split("/\s+/u", $string, 0, PREG_SPLIT_NO_EMPTY)); } public static function normalizeNumber($value) { $value = (string) $value; $localeInfo = localeconv(); $decimalSeparator = isset($localeInfo["decimal_point"]) ? $localeInfo["decimal_point"] : null; if ($decimalSeparator !== null && $decimalSeparator !== ".") { $value = str_replace($decimalSeparator, ".", $value); } return $value; } public static function base64UrlEncode($input) { return strtr(base64_encode($input), "+/", "-_"); } public static function base64UrlDecode($input) { return base64_decode(strtr($input, "-_", "+/")); } public static function floatToString($number) { return str_replace(",", ".", (string) $number); } public static function matchWildcard($pattern, $string, $options = array()) { if ($pattern === "*" && empty($options["filePath"])) { return true; } $replacements = array("\\" => "\", "\\*" => "[*]", "\\?" => "[?]", "\*" => ".*", "\?" => ".", "\[\!" => "[^", "\[" => "[", "\]" => "]", "\-" => "-"); if (isset($options["escape"]) && !$options["escape"]) { unset($replacements["\\"]); unset($replacements["\\*"]); unset($replacements["\\?"]); } if (!empty($options["filePath"])) { $replacements["\*"] = "[^/\]*"; $replacements["\?"] = "[^/\]"; } $pattern = strtr(preg_quote($pattern, "#"), $replacements); $pattern = "#^" . $pattern . "$#us"; if (isset($options["caseSensitive"]) && !$options["caseSensitive"]) { $pattern .= "i"; } return preg_match($pattern, (string) $string) === 1; } public static function mb_ucfirst($string, $encoding = "UTF-8") { $firstChar = mb_substr((string) $string, 0, 1, $encoding); $rest = mb_substr((string) $string, 1, null, $encoding); return mb_strtoupper($firstChar, $encoding) . $rest; } public static function mb_ucwords($string, $encoding = "UTF-8") { $string = (string) $string; if (empty($string)) { return $string; } $parts = preg_split("/(\s+\W+\s+|^\W+\s+|\s+)/u", $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $ucfirstEven = trim(mb_substr($parts[0], -1, 1, $encoding)) === ''; foreach ($parts as $key => $value) { $isEven = (bool) ($key % 2); if ($ucfirstEven === $isEven) { $parts[$key] = static::mb_ucfirst($value, $encoding); } } return implode('', $parts); } public static function mask($string, $start, $length, $mask = "*") { $strLength = mb_strlen($string, "UTF-8"); if ($start >= $strLength || $start < -$strLength) { return $string; } $masked = mb_substr($string, 0, $start, "UTF-8"); $masked .= str_repeat($mask, abs($length)); $masked .= mb_substr($string, $start + abs($length), null, "UTF-8"); return $masked; } public static function findBetween($string, $start, $end) { $startPos = mb_strpos($string, $start); if ($startPos === false) { return null; } $startPos += mb_strlen($start); $endPos = mb_strrpos($string, $end, $startPos); if ($endPos === false) { return null; } return mb_substr($string, $startPos, $endPos - $startPos); } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace yii\helpers; use Yii; class BaseStringHelper { public static function byteLength($string) { return mb_strlen((string) $string, "\70\x62\151\x74"); } public static function byteSubstr($string, $start, $length = null) { if ($length === null) { $length = static::byteLength($string); } return mb_substr((string) $string, $start, $length, "\x38\142\x69\x74"); } public static function basename($path, $suffix = '') { $path = (string) $path; $len = mb_strlen($suffix); if ($len > 0 && mb_substr($path, -$len) === $suffix) { $path = mb_substr($path, 0, -$len); } $path = rtrim(str_replace("\x5c", "\57", $path), "\57"); $pos = mb_strrpos($path, "\x2f"); if ($pos !== false) { return mb_substr($path, $pos + 1); } return $path; } public static function dirname($path) { $normalizedPath = rtrim(str_replace("\x5c", "\x2f", (string) $path), "\x2f"); $separatorPosition = mb_strrpos($normalizedPath, "\x2f"); if ($separatorPosition !== false) { return mb_substr($path, 0, $separatorPosition); } return ''; } public static function truncate($string, $length, $suffix = "\x2e\x2e\56", $encoding = null, $asHtml = false) { $string = (string) $string; if ($encoding === null) { $encoding = Yii::$app ? Yii::$app->charset : "\125\124\106\x2d\70"; } if ($asHtml) { return static::truncateHtml($string, $length, $suffix, $encoding); } if (mb_strlen($string, $encoding) > $length) { return rtrim(mb_substr($string, 0, $length, $encoding)) . $suffix; } return $string; } public static function truncateWords($string, $count, $suffix = "\x2e\x2e\x2e", $asHtml = false) { if ($asHtml) { return static::truncateHtml($string, $count, $suffix); } $words = preg_split("\x2f\x28\134\x73\x2b\51\57\x75", trim($string), 0, PREG_SPLIT_DELIM_CAPTURE); if (count($words) / 2 > $count) { return implode('', array_slice($words, 0, $count * 2 - 1)) . $suffix; } return $string; } protected static function truncateHtml($string, $count, $suffix, $encoding = false) { $config = \HTMLPurifier_Config::create(null); if (Yii::$app !== null) { $config->set("\103\141\143\x68\x65\x2e\123\145\x72\x69\141\x6c\151\x7a\145\x72\x50\141\x74\150", Yii::$app->getRuntimePath()); } $lexer = \HTMLPurifier_Lexer::create($config); $tokens = $lexer->tokenizeHTML($string, $config, new \HTMLPurifier_Context()); $openTokens = array(); $totalCount = 0; $depth = 0; $truncated = array(); foreach ($tokens as $token) { if ($token instanceof \HTMLPurifier_Token_Start) { $openTokens[$depth] = $token->name; $truncated[] = $token; ++$depth; } elseif ($token instanceof \HTMLPurifier_Token_Text && $totalCount <= $count) { if (false === $encoding) { preg_match("\57\136\50\134\x73\x2a\x29\x2f\x75\155", $token->data, $prefixSpace) ?: ($prefixSpace = array('', '')); $token->data = $prefixSpace[1] . self::truncateWords(ltrim($token->data), $count - $totalCount, ''); $currentCount = self::countWords($token->data); } else { $token->data = self::truncate($token->data, $count - $totalCount, '', $encoding); $currentCount = mb_strlen($token->data, $encoding); } $totalCount += $currentCount; $truncated[] = $token; } elseif ($token instanceof \HTMLPurifier_Token_End) { if ($token->name === $openTokens[$depth - 1]) { --$depth; unset($openTokens[$depth]); $truncated[] = $token; } } elseif ($token instanceof \HTMLPurifier_Token_Empty) { $truncated[] = $token; } if ($totalCount >= $count) { if (0 < count($openTokens)) { krsort($openTokens); foreach ($openTokens as $name) { $truncated[] = new \HTMLPurifier_Token_End($name); } } break; } } $context = new \HTMLPurifier_Context(); $generator = new \HTMLPurifier_Generator($config, $context); return $generator->generateFromTokens($truncated) . ($totalCount >= $count ? $suffix : ''); } public static function startsWith($string, $with, $caseSensitive = true) { $string = (string) $string; $with = (string) $with; if (!($bytes = static::byteLength($with))) { return true; } if ($caseSensitive) { return strncmp($string, $with, $bytes) === 0; } $encoding = Yii::$app ? Yii::$app->charset : "\x55\124\x46\x2d\70"; $string = static::byteSubstr($string, 0, $bytes); return mb_strtolower($string, $encoding) === mb_strtolower($with, $encoding); } public static function endsWith($string, $with, $caseSensitive = true) { $string = (string) $string; $with = (string) $with; if (!($bytes = static::byteLength($with))) { return true; } if ($caseSensitive) { if (static::byteLength($string) < $bytes) { return false; } return substr_compare($string, $with, -$bytes, $bytes) === 0; } $encoding = Yii::$app ? Yii::$app->charset : "\x55\x54\x46\55\x38"; $string = static::byteSubstr($string, -$bytes); return mb_strtolower($string, $encoding) === mb_strtolower($with, $encoding); } public static function explode($string, $delimiter = "\54", $trim = true, $skipEmpty = false) { $result = explode($delimiter, $string); if ($trim !== false) { if ($trim === true) { $trim = "\164\162\151\155"; } elseif (!is_callable($trim)) { $trim = function ($v) use($trim) { return trim($v, $trim); }; } $result = array_map($trim, $result); } if ($skipEmpty) { $result = array_values(array_filter($result, function ($value) { return $value !== ''; })); } return $result; } public static function countWords($string) { return count(preg_split("\x2f\x5c\163\x2b\x2f\x75", $string, 0, PREG_SPLIT_NO_EMPTY)); } public static function normalizeNumber($value) { $value = (string) $value; $localeInfo = localeconv(); $decimalSeparator = isset($localeInfo["\x64\145\143\x69\x6d\x61\154\x5f\160\x6f\x69\x6e\164"]) ? $localeInfo["\144\145\x63\151\155\x61\x6c\x5f\160\x6f\x69\156\164"] : null; if ($decimalSeparator !== null && $decimalSeparator !== "\56") { $value = str_replace($decimalSeparator, "\x2e", $value); } return $value; } public static function base64UrlEncode($input) { return strtr(base64_encode($input), "\x2b\57", "\55\137"); } public static function base64UrlDecode($input) { return base64_decode(strtr($input, "\55\137", "\53\57")); } public static function floatToString($number) { return str_replace("\54", "\56", (string) $number); } public static function matchWildcard($pattern, $string, $options = array()) { if ($pattern === "\x2a" && empty($options["\146\151\154\145\x50\x61\164\x68"])) { return true; } $replacements = array("\134\134\x5c\x5c" => "\134\x5c", "\134\x5c\134\x2a" => "\133\52\x5d", "\134\x5c\134\x3f" => "\133\x3f\x5d", "\134\52" => "\x2e\52", "\x5c\x3f" => "\x2e", "\x5c\x5b\134\41" => "\133\x5e", "\134\x5b" => "\133", "\x5c\135" => "\135", "\134\55" => "\55"); if (isset($options["\x65\163\143\141\160\145"]) && !$options["\145\163\x63\141\160\145"]) { unset($replacements["\134\134\134\134"]); unset($replacements["\x5c\x5c\134\x2a"]); unset($replacements["\134\134\134\77"]); } if (!empty($options["\x66\151\x6c\145\x50\x61\x74\x68"])) { $replacements["\x5c\52"] = "\x5b\136\57\134\134\135\x2a"; $replacements["\134\77"] = "\x5b\x5e\x2f\x5c\x5c\x5d"; } $pattern = strtr(preg_quote($pattern, "\43"), $replacements); $pattern = "\x23\136" . $pattern . "\44\43\165\x73"; if (isset($options["\143\141\x73\145\x53\145\156\x73\151\164\151\166\x65"]) && !$options["\143\x61\x73\x65\123\x65\156\163\x69\164\151\x76\x65"]) { $pattern .= "\x69"; } return preg_match($pattern, (string) $string) === 1; } public static function mb_ucfirst($string, $encoding = "\x55\124\106\x2d\70") { $firstChar = mb_substr((string) $string, 0, 1, $encoding); $rest = mb_substr((string) $string, 1, null, $encoding); return mb_strtoupper($firstChar, $encoding) . $rest; } public static function mb_ucwords($string, $encoding = "\x55\124\106\55\x38") { $string = (string) $string; if (empty($string)) { return $string; } $parts = preg_split("\x2f\50\x5c\163\x2b\x5c\x57\x2b\134\x73\x2b\174\136\x5c\x57\x2b\134\163\x2b\174\x5c\163\x2b\x29\x2f\x75", $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $ucfirstEven = trim(mb_substr($parts[0], -1, 1, $encoding)) === ''; foreach ($parts as $key => $value) { $isEven = (bool) ($key % 2); if ($ucfirstEven === $isEven) { $parts[$key] = static::mb_ucfirst($value, $encoding); } } return implode('', $parts); } public static function mask($string, $start, $length, $mask = "\x2a") { $strLength = mb_strlen($string, "\125\124\106\55\x38"); if ($start >= $strLength || $start < -$strLength) { return $string; } $masked = mb_substr($string, 0, $start, "\x55\x54\106\55\70"); $masked .= str_repeat($mask, abs($length)); $masked .= mb_substr($string, $start + abs($length), null, "\x55\x54\x46\x2d\70"); return $masked; } public static function findBetween($string, $start, $end) { $startPos = mb_strpos($string, $start); if ($startPos === false) { return null; } $startPos += mb_strlen($start); $endPos = mb_strrpos($string, $end, $startPos); if ($endPos === false) { return null; } return mb_substr($string, $startPos, $endPos - $startPos); } }

Function Calls

None

Variables

None

Stats

MD5 1e5f61139758023fe4ec33b5cc788647
Eval Count 0
Decode Time 102 ms