本文整理汇总了PHP中chunk_split函数的典型用法代码示例。如果您正苦于以下问题:PHP chunk_split函数的具体用法?PHP chunk_split怎么用?PHP chunk_split使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了chunk_split函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: my_inet_ntop
function my_inet_ntop($ip)
{
if (strlen($ip) == 4) {
// ipv4
list(, $ip) = unpack('N', $ip);
$ip = long2ip($ip);
} elseif (strlen($ip) == 16) {
// ipv6
$ip = bin2hex($ip);
$ip = substr(chunk_split($ip, 4, ':'), 0, -1);
$ip = explode(':', $ip);
$res = '';
foreach ($ip as $seg) {
while ($seg[0] == '0') {
$seg = substr($seg, 1);
}
if ($seg != '') {
$res .= ($res == '' ? '' : ':') . $seg;
} else {
if (strpos($res, '::') === false) {
if (substr($res, -1) == ':') {
continue;
}
$res .= ':';
continue;
}
$res .= ($res == '' ? '' : ':') . '0';
}
}
$ip = $res;
}
return $ip;
}
示例2: send_email
function send_email($from, $to, $subject, $msg, $attachment)
{
$headers = "MIME-Version: 1.0\r\n" . $from;
$rand = md5(time());
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $rand . "\"\r\n\r\n";
$headers .= "--" . $rand . "\r\n";
$headers .= "Content-Type: text/html; charset=\"UTF-8\"\r\nContent-Transfer-Encoding: 8bit\r\n\r\n";
$headers .= $msg . "\r\n\r\n";
if (count($attachment) > 0) {
foreach ($attachment as $file) {
if (is_file($file)) {
$content = chunk_split(base64_encode(read_file($file)));
$headers .= "--" . $rand . "\r\n";
$headers .= "Content-Type: application/octet-stream; name=\"" . basename($file) . "\"\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment\r\n\r\n";
$headers .= $content . "\r\n\r\n";
}
}
}
$headers .= "--" . $rand . "--\r\n";
if (@mail($to, $subject, "", $headers)) {
return true;
}
return false;
}
示例3: insertKiiconnect
function insertKiiconnect()
{
global $databaseKiiconnect;
$data = json_decode(stripslashes($_POST["data"]));
$update["nombre"] = MySQL::SQLValue($data->nombre);
$update["tag"] = MySQL::SQLValue($data->tag);
$update["descripcion"] = MySQL::SQLValue($data->descripcion);
$update["icono"] = MySQL::SQLValue($data->icono);
$update["link"] = MySQL::SQLValue($data->link);
$update["orden"] = MySQL::SQLValue($data->orden);
$update["id_categoria"] = MySQL::SQLValue($data->id_categoria);
$update["activo"] = MySQL::SQLValue($data->activo, MySQL::SQLVALUE_NUMBER);
$databaseKiiconnect->InsertRow("kiiconnect_setting", $update);
echo json_encode(array("success" => $databaseKiiconnect->ErrorNumber() == 0, "msg" => $databaseKiiconnect->ErrorNumber() == 0 ? "Parametro insertado exitosamente" : $databaseKiiconnect->ErrorNumber(), "data" => array(array("id" => $databaseKiiconnect->GetLastInsertID(), "nombre" => $data->nombre, "tag" => $data->tag, "descripcion" => $data->descripcion, "icono" => $data->icono, "link" => $data->link, "orden" => $data->orden, "id_categoria" => $data->id_categoria, "activo" => $data->activo))));
//inserto como blob la imagen
$file = __DIR__ . '/../../../../' . $data->icono;
if ($fp = fopen($file, "rb", 0)) {
$picture = fread($fp, filesize($file));
fclose($fp);
// base64 encode the binary data, then break it
// into chunks according to RFC 2045 semantics
$base64 = chunk_split(base64_encode($picture));
$tag = 'data:image/png;base64,' . $base64;
}
$lastId = $databaseKiiconnect->GetLastInsertID();
$databaseKiiconnect->Query("update kiiconnect_setting set file='{$tag}' where `id`='{$lastId}'");
}
示例4: convert2vcf
function convert2vcf($data)
{
//
//mapping uebimiau key to vcf key
//
$ldap_key = array("name" => "FN", "email" => "EMAIL;PREF;INTERNET", "street" => "ADR;WORK", "work" => "TITLE");
$ldapfile = "BEGIN:VCARD\r\nVERSION:2.1\r\n";
foreach ($data as $key => $value) {
if ($key != "city" and $key != "state") {
$testo = $key == "street" ? ";;" . $data["street"] . ";" . $data["city"] . ";;;" . $data["state"] : $value;
if (ereg("[@,\r,\\(,\\),;,:]", $value)) {
$testo = urlencode($testo);
$testo = ereg_replace("\\+", " ", $testo);
$testo = ereg_replace("%", "=", $testo);
$testo = chunk_split($testo, 76, "=\r\n");
$testo = substr($testo, 0, strlen($testo) - 3);
$ldapfile .= $ldap_key[$key] . ";ENCODING=QUOTED-PRINTABLE:{$testo}\r\n";
} else {
$ldapfile .= $ldap_key[$key] . ":{$testo}\r\n";
}
}
}
$ldapfile .= "REV:" . date("Ymd\\This", time()) . "\r\n";
$ldapfile .= "END:VCARD";
return $ldapfile;
}
示例5: send_mail
function send_mail($to, $thm, $html, $path)
{
$fp = fopen($path, "r");
if (!$fp) {
print "Файл {$path} не может быть прочитан";
exit;
}
$file = fread($fp, filesize($path));
fclose($fp);
$boundary = "--" . md5(uniqid(time()));
// генерируем разделитель
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"{$boundary}\"\n";
$multipart .= "--{$boundary}\n";
$kod = 'utf-8';
// или $kod = 'windows-1251';
$multipart .= "Content-Type: text/html; charset={$kod}\n";
$multipart .= "Content-Transfer-Encoding: Quot-Printed\n\n";
$multipart .= "{$html}\n\n";
$message_part = "--{$boundary}\n";
$message_part .= "Content-Type: application/octet-stream\n";
$message_part .= "Content-Transfer-Encoding: base64\n";
$message_part .= "Content-Disposition: attachment; filename = \"" . $path . "\"\n\n";
$message_part .= chunk_split(base64_encode($file)) . "\n";
$multipart .= $message_part . "--{$boundary}--\n";
if (!mail($to, $thm, $multipart, $headers)) {
exit("К сожалению, письмо не отправлено");
}
}
示例6: enc_header
function enc_header($str, $charset = 'utf-8', $encoding = 'quoted-printable')
{
$enc = false;
if ($encoding == 'quoted-printable') {
if (!$this->is_printable($str)) {
$enc = $this->qpencode($str, $this->_hchunklen, $this->_crlf);
$enc = str_replace('?', '=3F', $enc);
}
} elseif ($encoding == 'base64') {
$enc = chunk_split(base64_encode($str), $this->_hchunklen, $this->_crlf);
}
if ($enc) {
$res = array();
$arr = explode($this->_crlf, $enc);
$chr = $encoding == 'base64' ? 'B' : 'Q';
foreach ($arr as $val) {
if ($val != '') {
$res[] = '=?' . $charset . '?' . $chr . '?' . $val . '?=';
}
}
return implode($this->_crlf . "\t", $res);
} else {
return $str;
}
}
示例7: displayOptions
public function displayOptions($options)
{
echo 'Options list:' . PHP_EOL;
$maxShortLength = 0;
$maxLongLength = 0;
$hasRequired = false;
foreach ($options as $option) {
if (($shortLength = strlen($option['short'])) > $maxShortLength) {
$maxShortLength = $shortLength;
}
if (($longLength = strlen($option['long'])) > $maxLongLength) {
$maxLongLength = $longLength;
}
$hasRequired = $hasRequired || $option['required'];
}
foreach ($options as $option) {
$line = $option['short'] ? '-' . $option['short'] . str_repeat(' ', $maxShortLength + self::SPACE_LENGTH - strlen($option['short'])) : str_repeat(' ', $maxShortLength + 1 + self::SPACE_LENGTH);
$line .= $option['long'] ? '--' . $option['long'] . str_repeat(' ', $maxLongLength + self::SPACE_LENGTH - strlen($option['long'])) : str_repeat(' ', $maxLongLength + 2 + self::SPACE_LENGTH);
$descrLength = strlen($option['description']);
$lineLength = strlen($line);
$leadingSpaces = str_repeat(' ', $maxShortLength + $maxLongLength + 3 + self::SPACE_LENGTH * 2);
if ($hasRequired) {
$line .= ($option['required'] ? '!' : ' ') . str_repeat(' ', self::SPACE_LENGTH);
$leadingSpaces .= str_repeat(' ', 1 + self::SPACE_LENGTH);
}
$line .= $lineLength < self::MAX_STR_LENGTH && self::MAX_STR_LENGTH < $descrLength + $lineLength ? rtrim(chunk_split($option['description'], self::MAX_STR_LENGTH - $lineLength, PHP_EOL . $leadingSpaces)) : $option['description'];
echo $line . PHP_EOL;
}
if ($hasRequired) {
echo PHP_EOL . '! - is for required options' . PHP_EOL;
}
}
示例8: sendmail
function sendmail()
{
global $curtime;
global $backupfile;
global $archname;
$text = "整站文件备份" . $backupfile;
$subject = $backupfile;
$from = 'wordpress@suifeng.me';
$to = 'webmaster@suifeng.me';
$file = $archname;
$boundary = uniqid("");
$headers = "From:{$from}\r\n";
$headers .= "Content-type:multipart/mixed; boundary= {$boundary}\r\n";
$mimeType = "application/x-bzip2";
$fileName = $backupfile;
$fp = fopen($file, "r");
$read = fread($fp, filesize($file));
$read = base64_encode($read);
$read = chunk_split($read);
$body = "--{$boundary}\nContent-type:text/plain; charset=utf-8\nContent-transfer-encoding: 8bit\n{$text}\n文件:{$backupfile}\n备份日期:{$curtime}\n--{$boundary}\nContent-type: {$mimeType}; name={$fileName}\nContent-disposition: attachment; filename={$fileName}\nContent-transfer-encoding: base64\n{$read}\n--{$boundary}--";
if (mail($to, $subject, $body, $headers)) {
print "OK! Now the mail from {$from} ---to--- {$to} has been send<br>";
} else {
print "fail to send mail <br>";
}
}
示例9: dw_send_mail_attachment
/**
* Send email an email with attachements
* @param $files - array of files to send
* ex: array(
* "my_image.png" => array(
* "path" => "/home/datawrapper/my_image.png",
* "format" => "image/png"
* )
* )
*
*/
function dw_send_mail_attachment($to, $from, $subject, $body, $files)
{
$random_hash = md5(date('r', time()));
// $random_hash = md5(date('r', time()));
$random_hash = '-----=' . md5(uniqid(mt_rand()));
// headers
$headers = 'From: ' . $from . "\n";
// $headers .= 'Return-Path: <'.$email_reply.'>'."\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-Type: multipart/mixed; boundary="' . $random_hash . '"';
// message
$message = 'This is a multi-part message in MIME format.' . "\n\n";
$message .= '--' . $random_hash . "\n";
$message .= 'Content-Type: text/plain; charset="iso-8859-1"' . "\n";
$message .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
$message .= $body . "\n\n";
// attached files
foreach ($files as $fn => $file) {
$path = $file["path"];
$format = $file["format"];
$attachment = chunk_split(base64_encode(file_get_contents($path)));
$message .= '--' . $random_hash . "\n";
$message .= 'Content-Type: ' . $format . '; name="' . $fn . '"' . "\n";
$message .= 'Content-Transfer-Encoding: base64' . "\n";
$message .= 'Content-Disposition:attachement; filename="' . $fn . '"' . "\n\n";
$message .= $attachment . "\n";
}
DatawrapperHooks::execute(DatawrapperHooks::SEND_EMAIL, $to, $subject, $message, $headers);
}
示例10: send
/**
* send
* 必有方法,发送时调用
*
* config参数为getOptions取得的所有项的配置结果
*
* @param mixed $to
* @param mixed $message
* @param mixed $config
* @access public
* @return void
*/
function send($to, $subject, $body, $config)
{
$this->Sender = $config['usermail'];
$this->Subject = $this->inlineCode($subject);
if (constant("ECAE_MODE")) {
// 保留原始的subject和body
$config['subject'] = $subject;
$config['body'] = $body;
}
$header = array('Return-path' => '<' . $config['usermail'] . '>', 'Date' => date('r'), 'From' => $this->inlineCode($config['shopname']) . '<' . $config['usermail'] . '>', 'MIME-Version' => '1.0', 'Subject' => $this->Subject, 'To' => $to, 'Content-Type' => 'text/html; charset=UTF-8; format=flowed', 'Content-Transfer-Encoding' => 'base64');
$config['sendway'] = $config['sendway'] ? $config['sendway'] : 'smtp';
if ($config['sendway'] == 'mail') {
unset($header['Subject']);
unset($header['To']);
}
$body = chunk_split(base64_encode($body));
$header = $this->buildHeader($header);
switch ($config['sendway']) {
case "sendmail":
$result = $this->SendmailSend($to, $header, $body);
break;
case "mail":
$result = $this->MailSend($to, $header, $body);
break;
case "smtp":
$result = $this->SmtpSend($to, $header, $body, $config);
break;
default:
// trigger_error('mailer_not_supported',E_ERROR);
$result = false;
break;
}
return $result;
}
示例11: escapeManual
/**
* Escapes the inserted value for LDAP.
*
* @param string $value
* @param string $ignore
* @param int $flags
*
* @return string
*/
protected static function escapeManual($value, $ignore = '', $flags = 0)
{
// If a flag was supplied, we'll send the value off
// to be escaped using the PHP flag values
// and return the result.
if ($flags) {
return static::escapeManualWithFlags($value, $ignore, $flags);
}
// Convert ignore string into an array.
$ignores = static::ignoreStrToArray($ignore);
// Convert the value to a hex string.
$hex = bin2hex($value);
// Separate the string, with the hex length of 2, and
// place a backslash on the end of each section.
$value = chunk_split($hex, 2, '\\');
// We'll append a backslash at the front of the string
// and remove the ending backslash of the string.
$value = '\\' . substr($value, 0, -1);
// Go through each character to ignore.
foreach ($ignores as $charToIgnore) {
// Convert the character to ignore to a hex.
$hexed = bin2hex($charToIgnore);
// Replace the hexed variant with the original character.
$value = str_replace('\\' . $hexed, $charToIgnore, $value);
}
// Finally we can return the escaped value.
return $value;
}
示例12: encode_headers
/**
* @param $in_str
* @param $charset
* @return string
*/
function encode_headers($in_str, $charset)
{
$out_str = $in_str;
if ($out_str && $charset) {
// define start delimimter, end delimiter and spacer
$end = "?=";
$start = "=?" . $charset . "?b?";
$spacer = $end . "\r\n" . $start;
// determine length of encoded text within chunks
// and ensure length is even
$length = 71 - strlen($spacer);
// no idea why 71 but 75 didn't work
$length = floor($length / 2) * 2;
// encode the string and split it into chunks
// with spacers after each chunk
$out_str = base64_encode($out_str);
$out_str = chunk_split($out_str, $length, $spacer);
// remove trailing spacer and
// add start and end delimiters
$spacer = preg_quote($spacer);
$out_str = preg_replace("/" . $spacer . "\$/", "", $out_str);
$out_str = $start . $out_str . $end;
}
return $out_str;
}
示例13: SendMail
static function SendMail($from, $to, $subject, $message, $options = null, $bcc = array())
{
global $INI;
$from = "{$INI['system']['sitename']} <{$from}>";
if (!isset($options['subjectenc'])) {
$options['subjectenc'] = 'GBK';
}
if (!isset($options['encoding'])) {
$options['encoding'] = 'UTF-8';
}
if (!isset($options['contentType'])) {
$options['contentType'] = 'text/plain';
}
if ('UTF-8' != $options['encoding']) {
$message = mb_convert_encoding($message, $options['encoding'], 'UTF-8');
}
$message = chunk_split(base64_encode($message));
$subject = self::EscapeHead($subject, $options['subjectenc']);
$from = self::EscapePart($from, $options['subjectenc']);
$to = self::EscapePart($to, $options['subjectenc']);
$headers = array("Mime-Version: 1.0", "Content-Type: {$options['contentType']}; charset={$options['encoding']}", "Content-Transfer-Encoding: base64", "X-Mailer: ZTMailer/1.0", "From: {$from}", "Reply-To: {$from}");
if ($bcc) {
$bcc = join(', ', $bcc);
$headers[] = "Bcc: {$bcc}";
}
$headers = join("\r\n", $headers);
if (isset($options['messageId'])) {
$headers["Message-Id"] = "<{$options['messageId']}>";
}
return mail($to, $subject, $message, $headers);
}
示例14: sl_send_email
function sl_send_email($to, $subject, $html, $plain = null, $attachment = null)
{
if (empty($to)) {
return false;
}
$hash = md5(date('r', time()));
$headers['From'] = 'The LoveMachine <love@sendlove.us>';
$headers['To'] = $to;
if (!empty($html)) {
if (empty($plain)) {
$h2t = new html2text($html, 75);
$plain = $h2t->convert();
}
$headers["Content-Type"] = "multipart/alternative; boundary=\"PHP-alt-{$hash}\"";
$body = "\n--PHP-alt-{$hash}\nContent-Type: text/plain; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n\n" . $plain . "\n\n--PHP-alt-{$hash}\nContent-Type: text/html; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n\n" . $html . "\n\n--PHP-alt-{$hash}--";
if ($attachment != null && !empty($attachment['name']) && !empty($attachment['content'])) {
$headers["Content-Type"] = "multipart/mixed; boundary=\"PHP-mixed-{$hash}\"";
//encode it with MIME base64,
//and split it into smaller chunks
$attachmentContent = chunk_split(base64_encode($attachment['content']));
$body = "\n--PHP-mixed-{$hash}\nContent-Type: multipart/alternative; boundary=\"PHP-alt-{$hash}\"\n\n" . $body . "\n--PHP-mixed-{$hash} \nContent-Type: {$attachment['type']}; name=\"{$attachment['name']}\" \nContent-Transfer-Encoding: base64 \nContent-Disposition: attachment \n\n{$attachmentContent}\n--PHP-mixed-{$hash}-- \n";
}
} else {
$body = $plain;
}
send_authmail(array('sender' => 'authuser', 'server' => 'gmail-ssl'), $to, $subject, $body, $headers);
return true;
}
示例15: _guifi_mac_sum
function _guifi_mac_sum($mac, $sum)
{
$mac = str_replace(":", "", $mac);
$dec = hexdec($mac) + $sum;
$smac = str_pad(dechex($dec), 12, '0', STR_PAD_LEFT);
return strtoupper(substr(chunk_split($smac, 2, ':'), 0, 17));
}