Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1820608
StringUtil.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Size
1 KB
Subscribers
None
StringUtil.php
View Options
<?php
namespace
Sabre\VObject
;
/**
* Useful utilities for working with various strings.
*
* @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class
StringUtil
{
/**
* Returns true or false depending on if a string is valid UTF-8
*
* @param string $str
* @return bool
*/
static
public
function
isUTF8
(
$str
)
{
// Control characters
if
(
preg_match
(
'%[
\x
00-
\x
08
\x
0B-
\x
0C
\x
0E
\x
0F]%'
,
$str
))
{
return
false
;
}
return
(
bool
)
preg_match
(
'%%u'
,
$str
);
}
/**
* This method tries its best to convert the input string to UTF-8.
*
* Currently only ISO-5991-1 input and UTF-8 input is supported, but this
* may be expanded upon if we receive other examples.
*
* @param string $str
* @return string
*/
static
public
function
convertToUTF8
(
$str
)
{
$encoding
=
mb_detect_encoding
(
$str
,
array
(
'UTF-8'
,
'ISO-8859-1'
,
'WINDOWS-1252'
),
true
);
switch
(
$encoding
)
{
case
'ISO-8859-1'
:
$newStr
=
utf8_encode
(
$str
);
break
;
/* Unreachable code. Not sure yet how we can improve this
* situation.
case 'WINDOWS-1252' :
$newStr = iconv('cp1252', 'UTF-8', $str);
break;
*/
default
:
$newStr
=
$str
;
}
// Removing any control characters
return
(
preg_replace
(
'%(?:[
\x
00-
\x
08
\x
0B-
\x
0C
\x
0E-
\x
1F
\x
7F])%'
,
''
,
$newStr
));
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Dec 22, 6:51 AM (5 d, 4 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
915538
Default Alt Text
StringUtil.php (1 KB)
Attached To
rDAVCAL DokuWiki DAVCal PlugIn
Event Timeline
Log In to Comment