-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHtmlSpecialcharsEncoder.php
More file actions
38 lines (33 loc) · 1006 Bytes
/
HtmlSpecialcharsEncoder.php
File metadata and controls
38 lines (33 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace VStelmakh\UrlHighlight\Encoder;
/**
* Could be used when input string expected to be html special chars encoded (&, ", ', <, >)
*/
class HtmlSpecialcharsEncoder extends HtmlEntitiesEncoder
{
private const HTML_SPECIAL_CHARS = ['&', '"', '\'', '<', '>'];
/**
* If html special char, return regex to match: char or html entity or numeric character reference
* else return provided char regex safe
*
* @param string $char
* @param string $delimiter
* @return string
*/
public function getEncodedCharRegex(string $char, string $delimiter = '/'): string
{
return \in_array($char, self::HTML_SPECIAL_CHARS, true)
? parent::getEncodedCharRegex($char)
: preg_quote($char, $delimiter);
}
/**
* Return html special chars
*
* @return string[]|null
*/
public function getSupportedChars(): ?array
{
return self::HTML_SPECIAL_CHARS;
}
}