-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.php
More file actions
37 lines (33 loc) · 859 Bytes
/
module.php
File metadata and controls
37 lines (33 loc) · 859 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
<?php
namespace TryPhp;
/**
* Function to strip control characters from a string, weak ones like \t and \n will be just replaced with a single space to
* keep the semantical correctness of the text
* @param string $content
* @return string
*/
function stripControlCharacters(string $content): string {
$removedStrongControlCharacters = str_replace([
"\a",
"\0",
"\b",
"\v",
"\f",
"\r",
"\e"
], '', $content);
$replacedWeakControlCharacters = str_replace([
"\t",
"\n"
], ' ', $removedStrongControlCharacters);
return $replacedWeakControlCharacters;
}
/**
* Function to remove color escape characters from text content
* @param string $content
* @return string
*/
function stripColorCharacters(string $content): string {
$removedColorCharacter = preg_replace('/\\e\[\d+m/', '', $content);
return $removedColorCharacter;
}