mirror of
https://github.com/getformwork/formwork.git
synced 2025-01-18 05:58:20 +01:00
Add Str::escapeAttr()
This commit is contained in:
parent
561649be2b
commit
001dfe2e51
@ -86,13 +86,21 @@ class Str
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape HTML tags from a given string
|
||||
* Escape HTML tags, quotes and ampersands from a given string
|
||||
*/
|
||||
public static function escape(string $string): string
|
||||
{
|
||||
return htmlspecialchars($string, ENT_COMPAT | ENT_SUBSTITUTE, 'utf-8', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape quotes and ampersands from a given string (to be used with HTML attributes)
|
||||
*/
|
||||
public static function escapeAttr(string $string): string
|
||||
{
|
||||
return str_replace(['<', '>'], ['<', '>'], static::escape($string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove HTML tags and entities from a given string
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user