本文整理汇总了PHP中rcube_charset::detect方法的典型用法代码示例。如果您正苦于以下问题:PHP rcube_charset::detect方法的具体用法?PHP rcube_charset::detect怎么用?PHP rcube_charset::detect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rcube_charset
的用法示例。
在下文中一共展示了rcube_charset::detect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
/**
*
*/
public function import($csv)
{
// convert to UTF-8
$head = substr($csv, 0, 4096);
$fallback = rcube::get_instance()->config->get('default_charset', 'ISO-8859-1');
// fallback to Latin-1?
$charset = rcube_charset::detect($head, RCUBE_CHARSET);
$csv = rcube_charset::convert($csv, $charset);
$head = '';
$this->map = array();
// Parse file
foreach (preg_split("/[\r\n]+/", $csv) as $i => $line) {
$elements = $this->parse_line($line);
if (empty($elements)) {
continue;
}
// Parse header
if (empty($this->map)) {
$this->parse_header($elements);
if (empty($this->map)) {
break;
}
} else {
$this->csv_to_vcard($elements);
}
}
}
示例2: import
/**
*
*/
public function import($csv)
{
// convert to UTF-8
$head = substr($csv, 0, 4096);
$charset = rcube_charset::detect($head, RCUBE_CHARSET);
$csv = rcube_charset::convert($csv, $charset);
$head = '';
$this->map = array();
// Parse file
foreach (preg_split("/[\r\n]+/", $csv) as $line) {
$elements = $this->parse_line($line);
if (empty($elements)) {
continue;
}
// Parse header
if (empty($this->map)) {
$this->parse_header($elements);
if (empty($this->map)) {
break;
}
} else {
$this->csv_to_vcard($elements);
}
}
}
示例3: import
/**
*
*/
public function import($csv)
{
// convert to UTF-8
$head = substr($csv, 0, 4096);
$charset = rcube_charset::detect($head, RCUBE_CHARSET);
$csv = rcube_charset::convert($csv, $charset);
$csv = preg_replace(array('/^[\\xFE\\xFF]{2}/', '/^\\xEF\\xBB\\xBF/', '/^\\x00+/'), '', $csv);
// also remove BOM
$head = '';
$prev_line = false;
$this->map = array();
$this->gmail_map = array();
// Parse file
foreach (preg_split("/[\r\n]+/", $csv) as $line) {
if (!empty($prev_line)) {
$line = '"' . $line;
}
$elements = $this->parse_line($line);
if (empty($elements)) {
continue;
}
// Parse header
if (empty($this->map)) {
$this->parse_header($elements);
if (empty($this->map)) {
break;
}
} else {
// handle multiline elements (e.g. Gmail)
if (!empty($prev_line)) {
$first = array_shift($elements);
if ($first[0] == '"') {
$prev_line[count($prev_line) - 1] = '"' . $prev_line[count($prev_line) - 1] . "\n" . substr($first, 1);
} else {
$prev_line[count($prev_line) - 1] .= "\n" . $first;
}
$elements = array_merge($prev_line, $elements);
}
$last_element = $elements[count($elements) - 1];
if ($last_element[0] == '"') {
$elements[count($elements) - 1] = substr($last_element, 1);
$prev_line = $elements;
continue;
}
$this->csv_to_vcard($elements);
$prev_line = false;
}
}
}
示例4: set_part_filename
//.........这里部分代码省略.........
$i++;
}
}
} else {
if (!empty($part->d_parameters['filename*0*'])) {
$i = 0;
while (isset($part->d_parameters['filename*' . $i . '*'])) {
$filename_encoded .= $part->d_parameters['filename*' . $i . '*'];
$i++;
}
if ($i < 2) {
if (!$headers) {
$headers = $this->conn->fetchPartHeader($this->folder, $this->msg_uid, true, $part->mime_id);
}
$filename_encoded = '';
$i = 0;
$matches = array();
while (preg_match('/filename\\*' . $i . '\\*\\s*=\\s*"*([^"\\n;]+)[";]*/', $headers, $matches)) {
$filename_encoded .= $matches[1];
$i++;
}
}
} else {
if (!empty($part->ctype_parameters['name*0'])) {
$i = 0;
while (isset($part->ctype_parameters['name*' . $i])) {
$filename_mime .= $part->ctype_parameters['name*' . $i];
$i++;
}
if ($i < 2) {
if (!$headers) {
$headers = $this->conn->fetchPartHeader($this->folder, $this->msg_uid, true, $part->mime_id);
}
$filename_mime = '';
$i = 0;
$matches = array();
while (preg_match('/\\s+name\\*' . $i . '\\s*=\\s*"*([^"\\n;]+)[";]*/', $headers, $matches)) {
$filename_mime .= $matches[1];
$i++;
}
}
} else {
if (!empty($part->ctype_parameters['name*0*'])) {
$i = 0;
while (isset($part->ctype_parameters['name*' . $i . '*'])) {
$filename_encoded .= $part->ctype_parameters['name*' . $i . '*'];
$i++;
}
if ($i < 2) {
if (!$headers) {
$headers = $this->conn->fetchPartHeader($this->folder, $this->msg_uid, true, $part->mime_id);
}
$filename_encoded = '';
$i = 0;
$matches = array();
while (preg_match('/\\s+name\\*' . $i . '\\*\\s*=\\s*"*([^"\\n;]+)[";]*/', $headers, $matches)) {
$filename_encoded .= $matches[1];
$i++;
}
}
} else {
if (!empty($part->ctype_parameters['name'])) {
$filename_mime = $part->ctype_parameters['name'];
} else {
if (!empty($part->headers['content-description'])) {
$filename_mime = $part->headers['content-description'];
} else {
return;
}
}
}
}
}
}
}
}
}
// decode filename
if (!empty($filename_mime)) {
if (!empty($part->charset)) {
$charset = $part->charset;
} else {
if (!empty($this->struct_charset)) {
$charset = $this->struct_charset;
} else {
$charset = rcube_charset::detect($filename_mime, $this->default_charset);
}
}
$part->filename = rcube_mime::decode_mime_string($filename_mime, $charset);
} else {
if (!empty($filename_encoded)) {
// decode filename according to RFC 2231, Section 4
if (preg_match("/^([^']*)'[^']*'(.*)\$/", $filename_encoded, $fmatches)) {
$filename_charset = $fmatches[1];
$filename_encoded = $fmatches[2];
}
$part->filename = rcube_charset::convert(urldecode($filename_encoded), $filename_charset);
}
}
}
示例5: fix_attachment_name
/**
* Fix attachment name encoding if needed/possible
*/
protected function fix_attachment_name($name, $part)
{
if ($name == rcube_charset::clean($name)) {
return $name;
}
// find charset from part or its parent(s)
if ($part->charset) {
$charsets[] = $part->charset;
} else {
// check first part (common case)
$n = strpos($part->mime_id, '.') ? preg_replace('/\\.[0-9]+$/', '', $part->mime_id) . '.1' : 1;
if (($_part = $this->mime_parts[$n]) && $_part->charset) {
$charsets[] = $_part->charset;
}
// check parents' charset
$items = explode('.', $part->mime_id);
for ($i = count($items) - 1; $i > 0; $i--) {
$last = array_pop($items);
$parent = $this->mime_parts[join('.', $items)];
if ($parent && $parent->charset) {
$charsets[] = $parent->charset;
}
}
}
if ($this->headers->charset) {
$charsets[] = $this->headers->charset;
}
if (empty($charsets)) {
$rcube = rcube::get_instance();
$charsets[] = rcube_charset::detect($name, $rcube->config->get('default_charset', RCUBE_CHARSET));
}
foreach (array_unique($charsets) as $charset) {
$_name = rcube_charset::convert($name, $charset);
if ($_name == rcube_charset::clean($_name)) {
if (!$part->charset) {
$part->charset = $charset;
}
return $_name;
}
}
return $name;
}
示例6: detect_encoding
/**
* Returns UNICODE type based on BOM (Byte Order Mark)
*
* @param string Input string to test
* @return string Detected encoding
*/
private static function detect_encoding($string)
{
$fallback = rcube::get_instance()->config->get('default_charset', 'ISO-8859-1');
// fallback to Latin-1
return rcube_charset::detect($string, $fallback);
}
示例7: rc_detect_encoding
function rc_detect_encoding($string, $failover = '')
{
return rcube_charset::detect($string, $failover);
}
示例8: test_detect
/**
* @dataProvider data_detect
*/
function test_detect($input, $fallback, $output)
{
$this->assertEquals($output, rcube_charset::detect($input, $fallback));
}
示例9: rc_detect_encoding
function rc_detect_encoding($string, $failover = '')
{
_deprecation_warning(__FUNCTION__);
return rcube_charset::detect($string, $failover);
}