本文整理汇总了PHP中Localization::detectCharset方法的典型用法代码示例。如果您正苦于以下问题:PHP Localization::detectCharset方法的具体用法?PHP Localization::detectCharset怎么用?PHP Localization::detectCharset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Localization
的用法示例。
在下文中一共展示了Localization::detectCharset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importVCard
function importVCard($filename, $module = 'Contacts')
{
global $current_user;
$lines = file($filename);
$start = false;
$contact = loadBean($module);
$contact->title = 'imported';
$contact->assigned_user_id = $current_user->id;
$fullname = '';
$email_suffix = 1;
for ($index = 0; $index < sizeof($lines); $index++) {
$line = $lines[$index];
// check the encoding and change it if needed
$locale = new Localization();
$encoding = $locale->detectCharset($line);
if ($encoding != $GLOBALS['sugar_config']['default_charset']) {
$line = $locale->translateCharset($line, $encoding);
}
$line = trim($line);
if ($start) {
//VCARD is done
if (substr_count(strtoupper($line), 'END:VCARD')) {
if (!isset($contact->last_name)) {
$contact->last_name = $fullname;
}
break;
}
$keyvalue = explode(':', $line);
if (sizeof($keyvalue) == 2) {
$value = $keyvalue[1];
for ($newindex = $index + 1; $newindex < sizeof($lines), substr_count($lines[$newindex], ':') == 0; $newindex++) {
$value .= $lines[$newindex];
$index = $newindex;
}
$values = explode(';', $value);
$key = strtoupper($keyvalue[0]);
$key = strtr($key, '=', '');
$key = strtr($key, ',', ';');
$keys = explode(';', $key);
if ($keys[0] == 'TEL') {
if (substr_count($key, 'WORK') > 0) {
if (substr_count($key, 'FAX') > 0) {
if (!isset($contact->phone_fax)) {
$contact->phone_fax = $value;
}
} else {
if (!isset($contact->phone_work)) {
$contact->phone_work = $value;
}
}
}
if (substr_count($key, 'HOME') > 0) {
if (substr_count($key, 'FAX') > 0) {
if (!isset($contact->phone_fax)) {
$contact->phone_fax = $value;
}
} else {
if (!isset($contact->phone_home)) {
$contact->phone_home = $value;
}
}
}
if (substr_count($key, 'CELL') > 0) {
if (!isset($contact->phone_mobile)) {
$contact->phone_mobile = $value;
}
}
if (substr_count($key, 'FAX') > 0) {
if (!isset($contact->phone_fax)) {
$contact->phone_fax = $value;
}
}
}
if ($keys[0] == 'N') {
if (sizeof($values) > 0) {
$contact->last_name = $values[0];
}
if (sizeof($values) > 1) {
$contact->first_name = $values[1];
}
if (sizeof($values) > 2) {
$contact->salutation = $values[2];
}
}
if ($keys[0] == 'FN') {
$fullname = $value;
}
}
if ($keys[0] == 'ADR') {
if (substr_count($key, 'WORK') > 0 && (substr_count($key, 'POSTAL') > 0 || substr_count($key, 'PARCEL') == 0)) {
if (!isset($contact->primary_address_street) && sizeof($values) > 2) {
$textBreaks = array("\n", "\r");
$vcardBreaks = array("=0A", "=0D");
$contact->primary_address_street = str_replace($vcardBreaks, $textBreaks, $values[2]);
}
if (!isset($contact->primary_address_city) && sizeof($values) > 3) {
$contact->primary_address_city = $values[3];
}
if (!isset($contact->primary_address_state) && sizeof($values) > 4) {
$contact->primary_address_state = $values[4];
//.........这里部分代码省略.........