Component
6 months ago
ITip
6 months ago
Parser
6 months ago
Property
6 months ago
Recur
6 months ago
Splitter
6 months ago
TimezoneGuesser
6 months ago
timezonedata
1 year ago
BirthdayCalendarGenerator.php
6 months ago
Cli.php
6 months ago
Component.php
6 months ago
DateTimeParser.php
6 months ago
Document.php
6 months ago
ElementList.php
6 months ago
EofException.php
6 months ago
FreeBusyData.php
6 months ago
FreeBusyGenerator.php
6 months ago
InvalidDataException.php
6 months ago
Node.php
6 months ago
PHPUnitAssertions.php
6 months ago
Parameter.php
6 months ago
ParseException.php
6 months ago
Property.php
6 months ago
Reader.php
6 months ago
Settings.php
6 months ago
StringUtil.php
6 months ago
TimeZoneUtil.php
6 months ago
UUIDUtil.php
6 months ago
VCardConverter.php
6 months ago
Version.php
6 months ago
Writer.php
6 months ago
StringUtil.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaVendor\Sabre\VObject; |
| 4 | |
| 5 | /** |
| 6 | * Useful utilities for working with various strings. |
| 7 | * |
| 8 | * @copyright Copyright (C) fruux GmbH (https://fruux.com/) |
| 9 | * @author Evert Pot (http://evertpot.com/) |
| 10 | * @license http://sabre.io/license/ Modified BSD License |
| 11 | */ |
| 12 | class StringUtil |
| 13 | { |
| 14 | /** |
| 15 | * Returns true or false depending on if a string is valid UTF-8. |
| 16 | * |
| 17 | * @param string $str |
| 18 | * |
| 19 | * @return bool |
| 20 | */ |
| 21 | public 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 | /** |
| 32 | * This method tries its best to convert the input string to UTF-8. |
| 33 | * |
| 34 | * Currently only ISO-5991-1 input and UTF-8 input is supported, but this |
| 35 | * may be expanded upon if we receive other examples. |
| 36 | * |
| 37 | * @param string $str |
| 38 | * |
| 39 | * @return string |
| 40 | */ |
| 41 | public static function convertToUTF8($str) |
| 42 | { |
| 43 | if (!mb_check_encoding($str, 'UTF-8') && mb_check_encoding($str, 'ISO-8859-1')) { |
| 44 | $str = mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1'); |
| 45 | } |
| 46 | |
| 47 | // Removing any control characters |
| 48 | return preg_replace('%(?:[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F])%', '', $str); |
| 49 | } |
| 50 | } |
| 51 |