/** * Afficher un lien mailto en masquant l'adresse de courriel pour les robots. * * @param string $mail_adresse * @param string $mail_sujet * @param string $texte_lien * @param string $mail_contenu * @param string $mail_copy * @return string */ function mailto($mail_adresse,$mail_sujet,$texte_lien,$mail_contenu='',$mail_copy='') { $mailto = 'mailto:'.$mail_adresse.'?subject='.$mail_sujet; $mailto.= ($mail_copy) ? '&cc='.$mail_copy : '' ; $mailto.= ($mail_contenu) ? '&body='.$mail_contenu : '' ; $tab_unicode_valeurs = utf8ToUnicode(str_replace(' ','%20',$mailto)); $href = '&#'.implode(';'.'&#',$tab_unicode_valeurs).';'; return '<a href="'.$href.'" class="lien_mail">'.$texte_lien.'</a>'; }
/** * utf8字符串分隔为unicode字符串 * @param string $str 要转换的字符串 * @param string $pre * @return string */ function segmentToUnicode($str, $pre = '') { $arr = array(); $str_len = mb_strlen($str, 'UTF-8'); for ($i = 0; $i < $str_len; $i++) { $s = mb_substr($str, $i, 1, 'UTF-8'); if ($s != ' ' && $s != ' ') { $arr[] = $pre . 'ux' . utf8ToUnicode($s); } } $arr = array_unique($arr); return implode(' ', $arr); }
function gracenote_obfuscateText($text) { require_once 'utf8ToUnicode.php'; // Copy-protection: encode the contents of each line. Will not encode anything inside of "<" and ">" characters (because that would break any HTML). $LINE_BREAK = "<br />"; // this is the format in which it comes out of the parser. $LT_UNICODE = 60; $GT_UNICODE = 62; $lines = explode($LINE_BREAK, $text); $lyrics = ""; $isInsideTag = false; foreach ($lines as $oneLine) { $charsFromLyrics = utf8ToUnicode($oneLine); foreach ($charsFromLyrics as $unicodeValue) { if ($isInsideTag) { $unicodeAsArray = array($unicodeValue); // assigned so it can be passed by reference. $lyrics .= unicodeToUtf8($unicodeAsArray); if ($GT_UNICODE == $unicodeValue) { $isInsideTag = false; } } else { if ($LT_UNICODE == $unicodeValue) { $lyrics .= "<"; $isInsideTag = true; } else { $lyrics .= "&#{$unicodeValue};"; } } } $lyrics .= $LINE_BREAK; } # Prevent over-encoding of special HTML-encoded characters. # TODO: Is it safe to just make sure all /&([0-9a-zA-Z]{2,4});/ are put back to normal text? $lyrics = str_replace("&nbsp;", " ", $lyrics); $lyrics = str_replace("&#160;", " ", $lyrics); // fb#42619 $lyrics = str_replace("&amp;", "&", $lyrics); // rt#35365 $lyrics = str_replace("&gt;", ">", $lyrics); // fb#16034 $lyrics = str_replace("&lt;", "<", $lyrics); return substr($lyrics, 0, strlen($lyrics) - strlen($LINE_BREAK)); }
function updateUnicode() { $db = new MySql(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DB); $sql = "SELECT\r\n `id`,\r\n `character`\r\n FROM\r\n `tomoe_character`\r\n WHERE\r\n `unicode` = 0\r\n LIMIT 0,5000;"; $result = $db->query($sql); $num_before = $db->num_rows; if ($num_before > 0) { $usc_4 = 0; foreach ($result as $r) { $usc_4 = utf8ToUnicode($r->character); $sql = " UPDATE\r\n tomoe_character\r\n SET\r\n unicode = {$usc_4['0']}\r\n WHERE id = {$r->id};"; //echo $sql; $db->update($sql); } echo "请刷新页面。" . time(); } else { echo "Unicode字段更新完毕"; } }
$cfile = new EfrontFile($certificate_tpl_id_rtf); } $template_data = file_get_contents($cfile['path']); $issued_data = unserialize($result[0]['issued_certificate']); if (sizeof($issued_data) > 1) { $certificate = $template_data; $certificate = str_replace("#organization#", utf8ToUnicode($issued_data['organization']), $certificate); $certificate = str_replace("#user_name#", utf8ToUnicode($issued_data['user_name']), $certificate); $certificate = str_replace("#user_surname#", utf8ToUnicode($issued_data['user_surname']), $certificate); $certificate = str_replace("#course_name#", utf8ToUnicode($issued_data['course_name']), $certificate); $certificate = str_replace("#grade#", utf8ToUnicode($issued_data['grade']), $certificate); if (eF_checkParameter($issued_data['date'], 'timestamp')) { $issued_data['date'] = formatTimestamp($issued_data['date']); } $certificate = str_replace("#date#", utf8ToUnicode($issued_data['date']), $certificate); $certificate = str_replace("#serial_number#", utf8ToUnicode($issued_data['serial_number']), $certificate); } $filename = "certificate_" . $_GET['user'] . ".rtf"; } else { $certificateDirectory = G_CERTIFICATETEMPLATEPATH; $selectedCertificate = $_GET['certificate_tpl']; $certificate = file_get_contents($certificateDirectory . $selectedCertificate); $filename = $_GET['certificate_tpl']; } $webserver = explode(' ', $_SERVER['SERVER_SOFTWARE']); //GET Server information from $_SERVER $webserver_type = explode('/', $webserver[0]); $filenameRtf = "certificate_" . $_GET['user'] . ".rtf"; $filenamePdf = G_ROOTPATH . "www/phplivedocx/samples/mail-merge/convert/certificate_" . $_GET['user'] . ".pdf"; file_put_contents(G_ROOTPATH . "www/phplivedocx/samples/mail-merge/convert/certificate_" . $_GET['user'] . ".rtf", $certificate); if (mb_stripos($webserver_type[0], "IIS") === false) {
function check_string($ics) { $ics_file = explode("\n", $ics); foreach ($ics_file as $line => $str) { if (false === utf8ToUnicode($str)) { $error[] = $line; } } if (isset($error) && is_array($error)) { foreach ($error as $line) { dbg_error_log("LOG check_string", "error on lines % invalid character in string %s", $line + 1, $ics_file[$line]); return false; } } else { dbg_error_log("LOG check_string", "the string is UTF8 compliant"); return true; } }
/** * 将标签数组转换为unicode字符串 * @param array $tags 要转换的标签 * @param string $pre * @return string */ function tagToUnicode($tags, $pre = '') { $tags = array_unique($tags); $arr = array(); foreach ($tags as $tag) { $tmp = ''; $str_len = mb_strlen($tag, 'UTF-8'); for ($i = 0; $i < $str_len; $i++) { $s = mb_substr($tag, $i, 1, 'UTF-8'); if ($s != ' ' && $s != ' ') { $tmp .= 'ux' . utf8ToUnicode($s); } } if ($tmp != '') { $arr[] = $pre . $tmp; } } $arr = array_unique($arr); return implode(' ', $arr); }
function wpaUnicode($str) { $uni = utf8ToUnicode(utf8_encode($str)); $output = ''; foreach ($uni as $value) { $output .= '\\u' . str_pad(dechex($value), 4, '0', STR_PAD_LEFT); } return $output; }
/** * @see http://sourceforge.net/projects/phprtf */ function utf8Unicode($str) { return unicodeToEntitiesPreservingAscii(utf8ToUnicode($str)); }
/** * Detects the encoding of a particular text. * * @return string (GSM_7BIT|GSM_7BIT_EX|UTF16) */ public function detectEncoding($text, &$exChars) { if (!is_array($text)) { $text = utf8ToUnicode($text); } $utf16Chars = array_diff($text, $this->getGsm7bitExMap()); if (count($utf16Chars)) { return self::UTF16; } $exChars = array_intersect($text, $this->getAddedGsm7bitExMap()); if (count($exChars)) { return self::GSM_7BIT_EX; } return self::GSM_7BIT; }
$done = array(); foreach ($results as $key => $value) { if (preg_match('~^((alias\\s+[^ ]+\\s+)|(ISO[A-Z]+\\s+))([^ ]+)~', $value['d'], $matches)) { $from = $matches[4]; $from = preg_replace('~^&(.*);$~', '$1', $from); if (array_key_exists($from, $results)) { $value['d'] = $results[$from]['d']; } else { // print "\n\nUNKNOWN REF: $from ({$value['d']})\n"; } } $matches = array(); if (preg_match('~^&#x([A-Za-z0-9]*);$~', $value['v'], $matches)) { $ent = ltrim(strtolower($matches[1]), '0'); } else { $what = utf8ToUnicode($value['v']); $ent = ''; foreach ($what as $number) { $ent .= dechex($number); $ent .= ','; } $ent = rtrim($ent, ','); } $line = $ent . '=' . $value['d'] . "\n"; if (!empty($done[$ent])) { // Comment out duplicates. $line = '#' . $line; } $done[$ent] = true; print $line; $outfile .= $line;