ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
StringUtil.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\VObject;
4
13
21 static function isUTF8($str) {
22
23 // Control characters
24 if (preg_match('%[\x00-\x08\x0B-\x0C\x0E\x0F]%', $str)) {
25 return false;
26 }
27
28 return (bool)preg_match('%%u', $str);
29
30 }
31
42 static function convertToUTF8($str) {
43
44 $encoding = mb_detect_encoding($str, ['UTF-8', 'ISO-8859-1', 'WINDOWS-1252'], true);
45
46 switch ($encoding) {
47 case 'ISO-8859-1' :
48 $newStr = utf8_encode($str);
49 break;
50 /* Unreachable code. Not sure yet how we can improve this
51 * situation.
52 case 'WINDOWS-1252' :
53 $newStr = iconv('cp1252', 'UTF-8', $str);
54 break;
55 */
56 default :
57 $newStr = $str;
58
59 }
60
61 // Removing any control characters
62 return (preg_replace('%(?:[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F])%', '', $newStr));
63
64 }
65
66}
An exception for terminatinating execution or to throw for unit testing.
Useful utilities for working with various strings.
Definition: StringUtil.php:12
static convertToUTF8($str)
This method tries its best to convert the input string to UTF-8.
Definition: StringUtil.php:42
static isUTF8($str)
Returns true or false depending on if a string is valid UTF-8.
Definition: StringUtil.php:21