/** * Creates an instance of Stringy and invokes the given method with the * rest of the passed arguments. The optional encoding is expected to be * the last argument. For example, the following: * StaticStringy::slice('fòôbàř', 0, 3, 'UTF-8'); translates to * Stringy::create('fòôbàř', 'UTF-8')->slice(0, 3); * The result is not cast, so the return value may be of type Stringy, * integer, boolean, etc. * * @param string $name * @param mixed[] $arguments */ public static function __callStatic($name, $arguments) { if (!isset(static::$methodArgs[$name])) { throw new \BadMethodCallException($name . ' is not a valid method'); } $numArgs = count($arguments); $str = $numArgs ? $arguments[0] : ''; if ($numArgs === static::$methodArgs[$name]) { $args = array_slice($arguments, 1, -1); $encoding = $arguments[$numArgs - 1]; } else { $args = array_slice($arguments, 1); $encoding = null; } $stringy = Stringy::create($str, $encoding); return call_user_func_array(array($stringy, $name), $args); }
/** * Replaces all occurrences of $pattern in $str by $replacement. An alias * for mb_ereg_replace(). Note that the 'i' option with multibyte patterns * in mb_ereg_replace() requires PHP 5.4+. This is due to a lack of support * in the bundled version of Oniguruma in PHP 5.3. * * @param string $str The haystack to search through * @param string $pattern The regular expression pattern * @param string $replacement The string to replace with * @param string $options Matching conditions to be used * @param string $encoding The character encoding * @return string The resulting string after the replacements */ public static function regexReplace($str, $pattern, $replacement, $options = 'msr', $encoding = null) { return (string) Stringy::create($str, $encoding)->regexReplace($pattern, $replacement, $options, $encoding); }
/** * Convert all HTML entities to their applicable characters. * * @param string $str The string to decode. * @param int|null $flags See http://php.net/manual/en/function.html-entity-decode.php * @param string $encoding The character encoding * @return Stringy Object with the resulting $str after being html decoded. */ public static function htmlDecode($str, $flags = ENT_COMPAT, $encoding = null) { return (string) Stringy::create($str, $encoding)->htmlDecode($flags); }
/** * Creates an instance of Stringy and invokes the given method with the * rest of the passed arguments. The optional encoding is expected to be * the last argument. For example, the following: * StaticStringy::slice('fòôbàř', 0, 3, 'UTF-8'); translates to * Stringy::create('fòôbàř', 'UTF-8')->slice(0, 3); * The result is not cast, so the return value may be of type Stringy, * integer, boolean, etc. * * @param string $name * @param mixed[] $arguments * * @return Stringy */ public static function __callStatic($name, $arguments) { if (!static::$methodArgs) { $stringyClass = new \ReflectionClass('Stringy\\Stringy'); $methods = $stringyClass->getMethods(\ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { $params = $method->getNumberOfParameters() + 2; static::$methodArgs[$method->name] = $params; } } if (!isset(static::$methodArgs[$name])) { throw new \BadMethodCallException($name . ' is not a valid method'); } $numArgs = count($arguments); $str = $numArgs ? $arguments[0] : ''; if ($numArgs === static::$methodArgs[$name]) { $args = array_slice($arguments, 1, -1); $encoding = $arguments[$numArgs - 1]; } else { $args = array_slice($arguments, 1); $encoding = null; } $stringy = Stringy::create($str, $encoding); return call_user_func_array(array($stringy, $name), $args); }