当前位置: 首页>>代码示例>>PHP>>正文


PHP detect_encoding函数代码示例

本文整理汇总了PHP中detect_encoding函数的典型用法代码示例。如果您正苦于以下问题:PHP detect_encoding函数的具体用法?PHP detect_encoding怎么用?PHP detect_encoding使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了detect_encoding函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_detect_encoding

	public function test_detect_encoding()
	{
	    $this->assertTrue(test_detect_encoding());
	    
            $utf8_str = file_get_contents(dirname(__FILE__) . "/../tools/utf8_str.txt");
            $this->assertEquals("UTF-8", detect_encoding($utf8_str));
            $iso_str = file_get_contents(dirname(__FILE__) . "/../tools/iso-8859-1_str.txt");
            $this->assertEquals("ISO-8859-15", detect_encoding($iso_str));
	    
	}
开发者ID:rhertzog,项目名称:lcs,代码行数:10,代码来源:ShareIncTest.php

示例2: test_detect_encoding

function test_detect_encoding()
{
    if ("UTF-8" != detect_encoding("auie")) {echo 'échec ligne 45 mod_serveur/test_encoding_functions.php'; return false;} 
    if ("UTF-8" != detect_encoding("bépowǜdlj")) {echo 'échec ligne 46 mod_serveur/test_encoding_functions.php'; return false;} 
    if ("UTF-8" != detect_encoding(";œ€âũ")) {echo 'échec ligne 47 mod_serveur/test_encoding_functions.php'; return false;} 
    if ("UTF-8" != detect_encoding("é")) {echo 'échec ligne 48 mod_serveur/test_encoding_functions.php'; return false;}
    if ("ISO-8859-15" != detect_encoding("\xe9")) {echo 'échec ligne 48 mod_serveur/test_encoding_functions.php'; return false;}
    if ("ISO-8859-15" != detect_encoding("\xa4")) {echo 'échec ligne 48 mod_serveur/test_encoding_functions.php'; return false;}
	return true;
}
开发者ID:rhertzog,项目名称:lcs,代码行数:10,代码来源:test_encoding_functions.php

示例3: convert_encoding

function convert_encoding($string, $to_encoding, $from_encoding = '')
{
    if ($from_encoding == '') {
        $from_encoding = detect_encoding($string);
    }
    if ($from_encoding == $to_encoding) {
        return $string;
    }
    return mb_convert_encoding($string, $to_encoding, $from_encoding);
}
开发者ID:aouadiadib,项目名称:magazine_electronique,代码行数:10,代码来源:gallerie.php

示例4: __construct

 function __construct($area, $news_id, $author, $t_size, $t_seite, $make_thumb = true, $make_watermark = true, $flash_mode = false)
 {
     global $config, $db, $member_id;
     $this->allowed_files = explode(',', strtolower($config['files_type']));
     $this->area = totranslit($area);
     if ($config['charset'] == "windows-1251" and $config['charset'] != detect_encoding($author)) {
         $author = iconv("UTF-8", "windows-1251//IGNORE", $author);
     }
     $this->author = $db->safesql($author);
     $this->news_id = intval($news_id);
     $this->t_size = $t_size;
     $this->t_seite = $t_seite;
     $this->make_thumb = $make_thumb;
     $this->make_watermark = $make_watermark;
     $this->flash_mode = $flash_mode;
     if (isset($_FILES['qqfile'])) {
         $this->file = new UploadFileViaForm();
     } elseif (isset($_FILES['Filedata'])) {
         $this->file = new UploadFileViaFlash();
     } elseif ($_POST['imageurl'] != "") {
         $this->file = new UploadFileViaURL();
     } elseif ($member_id['user_group'] == 1 and $_POST['ftpurl'] != "") {
         $this->file = new UploadFileViaFTP();
     } else {
         $this->file = false;
     }
     if (@ini_get('safe_mode') == 1) {
         define('FOLDER_PREFIX', "");
     } else {
         define('FOLDER_PREFIX', date("Y-m") . "/");
     }
 }
开发者ID:Hadryan,项目名称:L2LWEB,代码行数:32,代码来源:upload.class.php

示例5: show_html_mail

 function show_html_mail()
 {
     $pre = array_var($_GET, 'pre');
     $filename = ROOT . "/tmp/" . $pre . "_temp_mail_content.html";
     if (!file_exists($filename)) {
         ajx_current("empty");
         return;
     }
     $content = file_get_contents($filename);
     $encoding = detect_encoding($content, array('UTF-8', 'ISO-8859-1', 'WINDOWS-1252'));
     header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Content-Type: text/html;charset=" . $encoding);
     header("Content-Length: " . (string) strlen($content));
     print $content;
     die;
 }
开发者ID:pnagaraju25,项目名称:fengoffice,代码行数:17,代码来源:MailController.class.php

示例6: detect_encoding

 // check and correct file encoding
 function detect_encoding($string)
 {
     $list = array('utf-8', 'iso-8859-15', 'iso-8859-1', 'iso-8859-3', 'windows-1251');
     foreach ($list as $item) {
         try {
             $sample = iconv($item, $item, $string);
             if (md5($sample) == md5($string)) {
                 return $item;
             }
         } catch (Exception $e) {
         }
     }
     return null;
 }
 $enc = detect_encoding($data);
 // works better than mb_detect_encoding($data);
 if (strtolower($enc) != "utf-8") {
     $data = mb_convert_encoding($data, "utf-8", $enc);
 }
 try {
     if ($result['success']) {
         $filename = $chart->writeData($data);
         $chart->save();
         //echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
         unlink($uploader->filename);
         ok($result);
     } else {
         error('upload-error', $result['error']);
     }
 } catch (Exception $e) {
开发者ID:shelsonjava,项目名称:datawrapper,代码行数:31,代码来源:charts.php

示例7: SaveMail


//.........这里部分代码省略.........
             $spam_email = MailSpamFilters::getFrom($account->getId(), $from);
             if ($spam_email) {
                 $state = 0;
                 if ($spam_email[0]->getSpamState() == "spam") {
                     $state = 4;
                 }
             } else {
                 if ($state == 0) {
                     if (strtolower($from) == strtolower($account->getEmailAddress())) {
                         if (strpos($to_addresses, $from) !== FALSE) {
                             $state = 5;
                         } else {
                             $state = 1;
                         }
                         //Show only in sent folder
                     }
                 }
             }
         }
         if (!isset($parsedMail['Subject'])) {
             $parsedMail['Subject'] = '';
         }
         $mail = new MailContent();
         $mail->setAccountId($account->getId());
         $mail->setState($state);
         $mail->setImapFolderName($imap_folder_name);
         $mail->setFrom($from);
         $cc = trim(self::getAddresses(array_var($parsedMail, "Cc")));
         if ($cc == '' && array_var($decoded, 0) && array_var($decoded[0], 'Headers')) {
             $cc = array_var($decoded[0]['Headers'], 'cc:', '');
         }
         $mail->setCc($cc);
         $from_name = trim(array_var(array_var(array_var($parsedMail, 'From'), 0), 'name'));
         $from_encoding = detect_encoding($from_name);
         if ($from_name == '') {
             $from_name = $from;
         } else {
             if (strtoupper($encoding) == 'KOI8-R' || strtoupper($encoding) == 'CP866' || $from_encoding != 'UTF-8' || !$enc_conv->isUtf8RegExp($from_name)) {
                 //KOI8-R and CP866 are Russian encodings which PHP does not detect
                 $utf8_from = $enc_conv->convert($encoding, 'UTF-8', $from_name);
                 if ($enc_conv->hasError()) {
                     $utf8_from = utf8_encode($from_name);
                 }
                 $utf8_from = utf8_safe($utf8_from);
                 $mail->setFromName($utf8_from);
             } else {
                 $mail->setFromName($from_name);
             }
         }
         $subject_aux = $parsedMail['Subject'];
         $subject_encoding = detect_encoding($subject_aux);
         $subject_multipart_encoding = array_var($parsedMail, 'SubjectEncoding', strtoupper($encoding));
         if ($subject_multipart_encoding != 'UTF-8' && ($subject_multipart_encoding == 'KOI8-R' || $subject_multipart_encoding == 'CP866' || $subject_encoding != 'UTF-8' || !$enc_conv->isUtf8RegExp($subject_aux))) {
             //KOI8-R and CP866 are Russian encodings which PHP does not detect
             $utf8_subject = $enc_conv->convert($subject_multipart_encoding, 'UTF-8', $subject_aux);
             if ($enc_conv->hasError()) {
                 $utf8_subject = utf8_encode($subject_aux);
             }
             $utf8_subject = utf8_safe($utf8_subject);
             $mail->setSubject($utf8_subject);
         } else {
             $utf8_subject = utf8_safe($subject_aux);
             $mail->setSubject($utf8_subject);
         }
         $mail->setTo($to_addresses);
         $sent_timestamp = false;
开发者ID:abhinay100,项目名称:fengoffice_app,代码行数:67,代码来源:MailUtilities.class.php

示例8: test

 public function test()
 {
     edump(md5('jinyanlin123456'));
     //Input::get('pass') == 'jUT4GlZtq3tHoPUE')
     exit;
     $phones = file_get_contents('phones.txt');
     $arr = preg_split('/\\s+/', $phones);
     $array = array_chunk($arr, intval(count($arr) / 3) + 1);
     $rse = [];
     foreach ($array as $k => $v) {
         $key = '7WQRJOnYAQUYGVSzke';
         $phone = $v;
         $message = '仁仁提醒:近期同学反馈有不法分子在百度留下私人电话冒充仁仁客服,对方会谎称同学还款失败需要重新还款,并要求将款项打入私人账户!请同学们提高警惕,如有任何问题先拨打官方唯一客服电话4007800087或风控部电话13454129972咨询!';
         $params = array('mobile' => implode(',', $phone), 'message' => $message);
         $params['pass'] = 'jUT4GlZtq3tHoPUE';
         $url = "https://secure.renrenfenqi.com/interface/crm/sms";
         $rse[] = curl_post($url, $params);
         sleep(2);
     }
     $url = "https://gw.alicdn.com/tps/i3/TB1QeiDGFXXXXb8XVXXszjdGpXX-140-140.png?imgtag=avatar";
     $content = file_get_contents($url);
     file_put_contents("TB1QeiDGFXXXXb8XVXXszjdGpXX-140-140.png", $content);
     exit;
     $content = file_get_contents('20160218');
     edump(detect_encoding($content));
     dump(__FUNCTION__);
     exit;
     $unit = new \App\Gather\RPG\UnitBase('Unit001');
     $unit->showDiedMessage();
     exit;
     $str = 'showInjuredMessage';
     dump(preg_replace('/[A-Z]/', '#\\0', $str));
     edump(preg_split('/[A-Z]/', $str));
     exit;
     if (version_compare(PHP_VERSION, '5.3.6', '>=')) {
         list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
     } else {
         list($current, $caller) = debug_backtrace(false, 2);
     }
     //         edump($backtrace);
     //         list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
     dump($current);
     edump($caller);
     \App\Gather\AESTool::main();
     exit;
     $url = 'http://www.xunshu.la/22_22665/7813282.html';
     $word = \Input::get('w');
     //         if(!$word){
     //             echo 'Word Is Required!';
     //             exit();
     //         }
     $sourceData = \App\Models\Transfer::all()->toArray();
     $transferData = [];
     $file = 'yun.xml';
     $content = file_get_contents($file);
     $resEN = $this->__xmlToArray($content);
     $n = 0;
     \DB::beginTransaction();
     foreach ($sourceData as $v) {
         if ($v['status'] == 0 && $v['eng'] != $resEN[$v['uid']]) {
             $str = html_entity_decode($resEN[$v['uid']]);
             $r = preg_replace('/<[^>]*>/', '', $str);
             preg_match_all('/[a-zA-Z]/i', $r, $metchs);
             if (count($metchs[0]) >= 1) {
                 continue;
             }
             echo $n . '[En]' . $v['eng'] . '<br/>';
             echo $n . '[Ch]' . $resEN[$v['uid']] . '<br/>';
             $n++;
             \App\Models\Transfer::where('id', $v['id'])->update(['status' => 2, 'chi' => htmlspecialchars($resEN[$v['uid']])]);
         }
     }
     \DB::commit();
     exit;
     foreach ($sourceData as $v) {
         $transferData[$v['contentuid']] = $v;
         $reg = '/' . $word . '/i';
         if ($word && preg_match($reg, $v['eng'])) {
             $str = preg_replace($reg, '<font color="red">\\0</font>', $v['eng']);
             echo '[EN]:' . $str . '<br/>';
             echo '[CH]:' . ($v['status'] == 1 ? $v['chi'] : '<textarea></textarea>') . '<br/>';
         }
     }
     //         dump($transferData);
     exit;
     exit;
     $fbsdk = \App\Services\Merchants\FBSdkService::getInstance();
     $file = 'english.xml';
     $content = file_get_contents($file);
     $resEN = $this->__xmlToArray($content);
     $file = 'hanhua.xml';
     $content = file_get_contents($file);
     $resCH = $this->__xmlToArray($content);
     //         $fp = fopen('result.xml', 'w');
     //         fputs($fp, '<?xml version="1.0" encoding="UTF-8" standalone="yes"?\>
     // <contentList>'.PHP_EOL);
     //         $fp1 = fopen('eng.xml', 'w');
     //         fputs($fp1, '<?xml version="1.0" encoding="UTF-8" standalone="yes"?\>
     // <contentList>'.PHP_EOL);
     $word = \Input::get('w');
//.........这里部分代码省略.........
开发者ID:ice-gyx,项目名称:transfer,代码行数:101,代码来源:GeneralTestController.php

示例9: intval

} else {
    $newsid = 0;
}
if (isset($_GET['cstart'])) {
    $cstart = intval($_GET['cstart']);
} else {
    $cstart = 0;
}
if (isset($_GET['news_page'])) {
    $news_page = intval($_GET['news_page']);
} else {
    $news_page = 0;
}
if (isset($_GET['user'])) {
    $user = @strip_tags(str_replace('/', '', urldecode($_GET['user'])));
    if ($config['charset'] == "windows-1251" and $config['charset'] != detect_encoding($user)) {
        $user = iconv("UTF-8", "windows-1251//IGNORE", $user);
    }
    $user = $db->safesql($user);
    if (preg_match("/[\\||\\'|\\<|\\>|\"|\\!|\\?|\$|\\@|\\/|\\\\|\\&\\~\\*\\+]/", $user)) {
        $user = "";
    }
} else {
    $user = '';
}
$category = '';
if (isset($_REQUEST['do'])) {
    $do = totranslit($_REQUEST['do']);
} else {
    $do = "";
}
开发者ID:Zzepish,项目名称:IvanShikalovWebSIte,代码行数:31,代码来源:print.php

示例10: __construct

 function __construct($area, $news_id, $author, $t_size, $t_seite, $make_thumb = true, $make_watermark = true, $flash_mode = false)
 {
     global $config, $db, $member_id, $user_group;
     $this->area = totranslit($area);
     if ($this->area == "adminupload") {
         if (!isset($_FILES['qqfile']) or $member_id['user_group'] != 1) {
             die("Hacking attempt!");
         }
         if ($_REQUEST['userdir']) {
             $userdir = totranslit($_REQUEST['userdir'], true, false) . "/";
         } else {
             $userdir = "";
         }
         if ($_REQUEST['subdir']) {
             $subdir = totranslit($_REQUEST['subdir'], true, false) . "/";
         } else {
             $subdir = "";
         }
         $this->upload_path = $userdir . $subdir;
         $this->use_prefix = false;
     } else {
         $this->allowed_files = explode(',', strtolower($user_group[$member_id['user_group']]['files_type']));
     }
     if ($config['charset'] == "windows-1251" and $config['charset'] != detect_encoding($author)) {
         if (function_exists('mb_convert_encoding')) {
             $author = mb_convert_encoding($author, "windows-1251", "UTF-8");
         } elseif (function_exists('iconv')) {
             $author = iconv("UTF-8", "windows-1251//IGNORE", $author);
         }
     }
     $this->author = $db->safesql($author);
     $this->news_id = intval($news_id);
     $this->t_size = $t_size;
     $this->t_seite = $t_seite;
     $this->make_thumb = $make_thumb;
     $this->make_watermark = $make_watermark;
     $this->flash_mode = $flash_mode;
     $ftp_upload_flag = false;
     if (isset($_FILES['qqfile'])) {
         $this->file = new UploadFileViaForm();
     } elseif (isset($_FILES['Filedata'])) {
         $this->file = new UploadFileViaFlash();
     } elseif ($_POST['imageurl'] != "") {
         $this->file = new UploadFileViaURL();
     } elseif ($member_id['user_group'] == 1 and $_POST['ftpurl'] != "") {
         $this->file = new UploadFileViaFTP();
         $ftp_upload_flag = true;
     } else {
         $this->file = false;
     }
     if (@ini_get('safe_mode') == 1 or $ftp_upload_flag or $this->area == "adminupload") {
         define('FOLDER_PREFIX', "");
     } else {
         define('FOLDER_PREFIX', date("Y-m") . "/");
     }
 }
开发者ID:Zzepish,项目名称:IvanShikalovWebSIte,代码行数:56,代码来源:upload.class.php

示例11: _parse_config_section

 function _parse_config_section($body)
 {
     $_result = array();
     preg_match_all('!(\\n\\s*[a-zA-Z0-9_]+)\\s*=\\s*(' . $this->_qstr_regexp . ')!s', $body, $ini);
     $keys = $ini[1];
     $values = $ini[2];
     for ($i = 0, $for_max = count($ini[0]); $i < $for_max; $i++) {
         if ($this->booleanize) {
             if (preg_match('/^(' . $this->_bool_true_regexp . ')$/i', $values[$i])) {
                 $values[$i] = true;
             } elseif (preg_match('/^(' . $this->_bool_false_regexp . ')$/i', $values[$i])) {
                 $values[$i] = false;
             }
         }
         if (!is_numeric($values[$i]) && !is_bool($values[$i])) {
             $values[$i] = str_replace("\n", '', stripslashes(substr($values[$i], 1, -1)));
             if (function_exists("iconv") && detect_encoding($values[$i]) != 'utf-8') {
                 $values[$i] = iconv('', 'UTF-8//IGNORE', $values[$i]);
             }
         }
         if ($this->overwrite || !isset($_result[trim($keys[$i])])) {
             $_result[trim($keys[$i])] = $values[$i];
         } else {
             if (!is_array($_result[trim($keys[$i])])) {
                 $_result[trim($keys[$i])] = array($_result[trim($keys[$i])]);
             }
             $_result[trim($keys[$i])][] = $values[$i];
         }
     }
     return $_result;
 }
开发者ID:bendroid,项目名称:pligg-cms,代码行数:31,代码来源:class.config.php

示例12: ensure_utf8

/**
 * Cette méthode prend une chaîne de caractères et s'assure qu'elle est bien retournée en UTF-8
 * Attention, certain encodages sont très similaire et ne peuve pas être théoriquement distingué sur une chaine de caractere.
 * Si vous connaissez déjà l'encodage de votre chaine de départ, il est préférable de le préciser
 * 
 * @param string $str La chaine à encoder
 * @param string $encoding L'encodage de départ
 * @return string La chaine en utf8
 * @throws Exception si la chaine n'a pas pu être encodée correctement
 */
function ensure_utf8($str, $from_encoding = null)
{
    if ($str === null || $str === '') {
        return $str;
    } else {
        if ($from_encoding == null && detect_utf8($str)) {
            return $str;
        }
    }
    if ($from_encoding != null) {
        $encoding = $from_encoding;
    } else {
        $encoding = detect_encoding($str);
    }
    $result = null;
    if ($encoding !== false && $encoding != null) {
        if (function_exists('mb_convert_encoding')) {
            $result = mb_convert_encoding($str, 'UTF-8', $encoding);
        }
    }
    if ($result === null || !detect_utf8($result)) {
        throw new Exception('Impossible de convertir la chaine vers l\'utf8');
    }
    return $result;
}
开发者ID:alhousseyni,项目名称:gepi,代码行数:35,代码来源:share.inc.php

示例13: get_url

?>
" action="<?php 
echo get_url('files', 'text_edit');
?>
" method="post" enctype="multipart/form-data">

	<div>
		<input type="hidden" name="file[id]" value="<?php 
echo $file->getId();
?>
" />
		<input type="hidden" name="file[name]" value="<?php 
echo clean($file->getFilename());
?>
" />
		<input type="hidden" name="file[encoding]" value="<?php 
echo detect_encoding($filecontent, array('UTF-8', 'ISO-8859-1'));
?>
" />
		<input type="hidden" name="new_revision_document" value="" />
 	</div>

	<textarea class="textedit" name="fileContent"><?php 
echo htmlEntities(EncodingConverter::instance()->convert(detect_encoding($filecontent, array('UTF-8', 'ISO-8859-1')), 'UTF-8', $filecontent), null, 'UTF-8');
?>
</textarea>
<?php 
add_page_action(lang("save"), "javascript:(function(){ var form = document.getElementById('{$iname}'); form.new_revision_document.value = 'checked'; form.onsubmit(); })()", "save");
?>
</form>
开发者ID:abhinay100,项目名称:feng_app,代码行数:30,代码来源:text_edit.php

示例14: implode

    $string = implode("", gzfile($srcName));
    $fp = fopen($dstName, "w");
    fwrite($fp, $string, strlen($string));
    fclose($fp);
}
$subs_file = file_get_contents("export.txt");
$subs = array();
preg_match_all("/.*[\\n\\r]+/iu", $subs_file, $matches);
foreach ($matches[0] as $line) {
    $subtitle = explode("\t", $line);
    if (!is_numeric($subtitle[1])) {
        continue;
    }
    uncompress('/home/soshial/subs/opensubtitles/' . $subtitle[1] . '.gz', '/home/soshial/subs/opensubtitles2/' . $subtitle[1] . '.srt');
    $sub_text = file_get_contents('/home/soshial/subs/opensubtitles2/' . $subtitle[1] . '.srt');
    if (detect_encoding($sub_text) == 'windows-1251') {
        $sub_text = strip_tags_smart(iconv('windows-1251', 'UTF-8//IGNORE', $sub_text));
    }
    // изменяем кодировку на юникод, и вычищаем от тегов
    $sub_text = preg_replace('/\\s*\\d+\\r\\n\\d\\d:\\d\\d:\\d\\d,\\d+ --> \\d\\d:\\d\\d:\\d\\d,\\d+/i', '', $sub_text, -1, $count);
    // вырезаем временные метки
    $sub_text = preg_replace('/\\.{2,}/i', '…', $sub_text, -1, $count);
    // заменяем многоточия
    /* склеиваем текст */
    $sub_text = preg_replace("/([^!…\\?_][a-z0-9а-яё])(\\s)*\\r\\n(\\s)*([…«\"\\-]{0,1}(\\s)*[a-zа-яё]{1,}[^\\)])/u", '$1 $4', $sub_text, -1, $count);
    // ориентация на отсутствие препинаний в конце первого параграфа и на строчные в начале второго п.,
    // где перед буквами могут находиться кавычки: «" и дефис
    // предполагается автоматическое объединение
    $sub_text = preg_replace("/([^!…\\?_][a-z0-9А-яё,;—–\\-\\»\\)IVX])(\\s)*\\r\\n(\\s)*([«\\(\\[\"\\-–—=…]{0,1}(\\s)*[a-z0-9а-яё\\?\\!…\"]+[^\\)])/u", '$1 $4', $sub_text, -1, $count);
    // ориентация на отсутствие точки в конце первого параграфа и на строчные в начале второго п.,
    // где перед буквами и цифрами могут находиться кавычки: «", дефис и скобки: ([
开发者ID:Braigns,项目名称:text-normalization,代码行数:31,代码来源:parse_subs.php

示例15: get_feed_data

/**
* get_feed_data($_params)
* returns the parsed feed.
* */
function get_feed_data($_params)
{
    global $user, $config;
    $feed_data = array('items' => array(), 'setup' => array('date' => false, 'author' => false, 'desclen' => 0, 'chantitle' => '', 'chanlink' => ''));
    @ini_set('user_agent', 'GYM Sitemaps &amp; RSS / www.phpBB-SEO.com');
    @ini_set('default_socket_timeout', 5);
    $xml = @file_get_contents($_params['url']);
    if ($xml) {
        // Get encoding
        $encoding = get_match('`encoding=[\'"]([a-z0-9_-]+)[\'"]`Usi', $xml);
        $encoding = !empty($encoding) ? strtolower($encoding) : detect_encoding($xml);
        if (preg_match('`<item>(.*)</item>`si', $xml, $matches)) {
            // Get chan info
            $feed_data['setup']['chantitle'] = get_match('`<title>(.*)</title>`Usi', $xml, $encoding);
            $feed_data['setup']['chanlink'] = get_match('`<link>(.*)</link>`Usi', $xml, $encoding);
            $xml = trim($matches[0]);
            unset($matches);
            preg_match_all('`<item>(.*)</item>`Usi', $xml, $matches);
            unset($matches[0]);
            if (!empty($matches[1]) && is_array($matches[1])) {
                $i = 1;
                foreach ($matches[1] as $key => $item) {
                    if ($i > $_params['limit']) {
                        break;
                    }
                    if ($title = get_match('`<title>(.*)</title>`Usi', $item, $encoding)) {
                        if ($link = get_match('`<link>(.*)</link>`Usi', $item, $encoding)) {
                            $feed_data['items'][$i]['PUBDATE'] = false;
                            if ($pubdate = get_match('`<pubDate>(.*)</pubDate>`Usi', $item, $encoding)) {
                                if (($pubdate = strtotime($pubdate, $user->time_now)) > 0) {
                                    $feed_data['items'][$i]['PUBDATE'] = $user->format_date($pubdate, $config['default_dateformat']);
                                    $feed_data['setup']['date'] = true;
                                }
                            }
                            $feed_data['items'][$i]['DESC'] = false;
                            if ($_params['desc'] && ($description = get_match('`<description>(.*)</description>`Usi', $item, $encoding))) {
                                if (empty($_params['html'])) {
                                    $description = htmlspecialchars($_params['striptags'] ? strip_tags($description) : $description, ENT_COMPAT, 'UTF-8');
                                }
                                $feed_data['items'][$i]['DESC'] = str_replace(array("\r", "\n"), '<br />', $description);
                                $feed_data['setup']['desclen'] += utf8_strlen($feed_data['items'][$i]['DESC']);
                            }
                            $feed_data['items'][$i]['SOURCE'] = false;
                            if ($source = get_match('`<source[\\s]+url="(.*)">(.*)</source>`Usi', $item, $encoding)) {
                                $feed_data['items'][$i]['SOURCE'] = htmlspecialchars($source, ENT_COMPAT, 'UTF-8');
                            }
                            $feed_data['items'][$i]['TITLE'] = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
                            $feed_data['items'][$i]['LINK'] = htmlspecialchars($link, ENT_COMPAT, 'UTF-8');
                            $feed_data['items'][$i]['IMG'] = $user->img('topic_read', $feed_data['items'][$i]['TITLE'], false, '', 'src');
                            $i++;
                        }
                    }
                    unset($matches[1][$key]);
                }
            }
            unset($matches);
        }
    }
    unset($xml);
    return $feed_data;
}
开发者ID:Ibrahim-Abdelkader,项目名称:phpbb3,代码行数:65,代码来源:gym_rss_functions.php


注:本文中的detect_encoding函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。