mirror of
https://github.com/danielstjules/Stringy.git
synced 2025-09-02 01:22:37 +02:00
html encode and decode
This commit is contained in:
@@ -866,4 +866,30 @@ class StaticStringy
|
||||
return (string) Stringy::create($str, $encoding)
|
||||
->regexReplace($pattern, $replacement, $options, $encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all applicable characters to HTML entities.
|
||||
*
|
||||
* @param string $str The string to encode.
|
||||
* @param int|null $flags See http://php.net/manual/en/function.htmlentities.php
|
||||
* @param string $encoding The character encoding
|
||||
* @return Stringy Object with the resulting $str after being html encoded.
|
||||
*/
|
||||
public static function htmlEncode($str, $flags = ENT_COMPAT, $encoding = null)
|
||||
{
|
||||
return (string) Stringy::create($str, $encoding)->htmlEncode($flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
@@ -1461,4 +1461,30 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess
|
||||
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all applicable characters to HTML entities.
|
||||
*
|
||||
* @param int|null $flags See http://php.net/manual/en/function.htmlentities.php
|
||||
* @return Stringy Object with the resulting $str after being html encoded.
|
||||
*/
|
||||
public function htmlEncode($flags = ENT_COMPAT)
|
||||
{
|
||||
$str = htmlentities($this->str, $flags, $this->encoding);
|
||||
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all HTML entities to their applicable characters.
|
||||
*
|
||||
* @param int|null $flags See http://php.net/manual/en/function.html-entity-decode.php
|
||||
* @return Stringy Object with the resulting $str after being html decoded.
|
||||
*/
|
||||
public function htmlDecode($flags = ENT_COMPAT)
|
||||
{
|
||||
$str = html_entity_decode($this->str, $flags, $this->encoding);
|
||||
|
||||
return static::create($str, $this->encoding);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user