iconv 函数 业 ,精于勤 荒于嬉.

iconv 函数 iconv_get_encoding 获取 iconv 扩展的内部配置变量

发表日期:2021-07-01 08:55:45 | 来源: | 分类:iconv 函数

      示例1
<?php 
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "ISO-8859-1");
var_dump(iconv_get_encoding('all'));
</pre>

阅读全文 »

iconv 函数 iconv_mime_decode_headers 一次性解码多个 MIME 头字段

发表日期:2021-07-01 08:55:45 | 来源: | 分类:iconv 函数

      示例1
<?php 
$headers_string = <<<EOFSubject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?=To: example@example.comDate: Thu, 1 Jan 1970 00:00:00 +0000Message-Id: <example@example.com>Received: from localhost (localhost [127.0.0.1]) by localhost    with SMTP id example for <example@example.com>;
    Thu, 1 Jan 1970 00:00:00 +0000 (UTC)    (envelope-from example-return-0000-example=example.com@example.com)Received: (qmail 0 invoked by uid 65534);
 1 Thu 2003 00:00:00 +0000EOF;
$headers =  iconv_mime_decode_headers($headers_string, 0, "ISO-8859-1");
print_r($headers);
?>

阅读全文 »

iconv 函数 iconv_mime_decode 解码一个MIME头字段

发表日期:2021-07-01 08:55:46 | 来源: | 分类:iconv 函数

      示例1
<?php 
//返回结果: "Subject: Prüfung Prüfung"
echo iconv_mime_decode("Subject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?=", 0, "ISO-8859-1");
?>

阅读全文 »

iconv 函数 iconv_mime_encode Composes a MIME header field

发表日期:2021-07-01 08:55:46 | 来源: | 分类:iconv 函数

      示例1
<?php 
$preferences = array("input-charset" => "ISO-8859-1","output-charset"=>"UTF-8","line-length"=>76,"line-break-chars" => "\n");
$preferences["scheme"] = "Q";
// This yields "Subject: =?UTF-8?Q?Pr=C3=BCfung=20Pr=C3=BCfung?="
echo iconv_mime_encode("Subject", "Prüfung Prüfung", $preferences);
$preferences["scheme"] = "B";
// This yields "Subject: =?UTF-8?B?UHLDvGZ1bmcgUHLDvGZ1bmc=?="
echo iconv_mime_encode("Subject", "Prüfung Prüfung", $preferences);
?>

阅读全文 »

iconv 函数 iconv_set_encoding 为字符编码转换设定当前设置

发表日期:2021-07-01 08:55:46 | 来源: | 分类:iconv 函数

      示例1
<?php 
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "ISO-8859-1");
?>

阅读全文 »

iconv 函数 iconv_strlen 返回字符串的字符数统计

发表日期:2021-07-01 08:55:46 | 来源: | 分类:iconv 函数

iconv_strlen

(PHP 5, PHP 7, PHP 8)

iconv_strlen返回字符串的字符数统计

说明

iconv_strlen(string $str, string $charset = ini_get("iconv.internal_encoding")): int

strlen() 不同的是,iconv_strlen() 统计了给定的字节序列 str 中出现字符数的统计,基于指定的字符集,其产生的结果不一定和字符字节数相等。

参数

str

该字符串。

charset

如果省略了 charset 参数,假设 str 的编码为 iconv.internal_encoding。

返回值

返回 str 字符数的统计,是整型。

参见

  • grapheme_strlen() - Get string length in grapheme units
  • mb_strlen() - 获取字符串的长度
  • strlen() - 获取字符串长度

阅读全文 »

iconv 函数 iconv_strpos Finds position of first occurrence of a needle within a haystack

发表日期:2021-07-01 08:55:46 | 来源: | 分类:iconv 函数

iconv_strpos

(PHP 5, PHP 7, PHP 8)

iconv_strposFinds position of first occurrence of a needle within a haystack

说明

iconv_strpos(
    string $haystack,
    string $needle,
    int $offset = 0,
    string|null $encoding = null
): int|false

Finds position of first occurrence of a needle within a haystack.

In contrast to strpos(), the return value of iconv_strpos() is the number of characters that appear before the needle, rather than the offset in bytes to the position where the needle has been found. The characters are counted on the basis of the specified character set encoding.

参数

haystack

The entire string.

needle

The searched substring.

offset

The optional offset parameter specifies the position from which the search should be performed. If the offset is negative, it is counted from the end of the string.

encoding

If encoding parameter is omitted or null, string are assumed to be encoded in iconv.internal_encoding.

If haystack or needle is not a string, it is converted to a string and applied as the ordinal value of a character.

返回值

Returns the numeric position of the first occurrence of needle in haystack.

If needle is not found, iconv_strpos() will return false.

警告

此函数可能返回布尔值 false,但也可能返回等同于 false 的非布尔值。请阅读 布尔类型章节以获取更多信息。应使用 === 运算符来测试此函数的返回值。

更新日志

版本 说明
8.0.0 encoding is nullable now.
7.1.0 Support for negative offsets has been added.

参见

  • strpos() - 查找字符串首次出现的位置
  • iconv_strrpos() - Finds the last occurrence of a needle within a haystack
  • mb_strpos() - 查找字符串在另一个字符串中首次出现的位置

阅读全文 »

iconv 函数 iconv_strrpos Finds the last occurrence of a needle within a haystack

发表日期:2021-07-01 08:55:46 | 来源: | 分类:iconv 函数

iconv_strrpos

(PHP 5, PHP 7, PHP 8)

iconv_strrposFinds the last occurrence of a needle within a haystack

说明

iconv_strrpos(string $haystack, string $needle, string|null $encoding = null): int|false

Finds the last occurrence of a needle within a haystack.

In contrast to strrpos(), the return value of iconv_strrpos() is the number of characters that appear before the needle, rather than the offset in bytes to the position where the needle has been found. The characters are counted on the basis of the specified character set encoding.

参数

haystack

The entire string.

needle

The searched substring.

encoding

If encoding parameter is omitted or null, string are assumed to be encoded in iconv.internal_encoding.

If haystack or needle is not a string, it is converted to a string and applied as the ordinal value of a character.

返回值

Returns the numeric position of the last occurrence of needle in haystack.

If needle is not found, iconv_strrpos() will return false.

警告

此函数可能返回布尔值 false,但也可能返回等同于 false 的非布尔值。请阅读 布尔类型章节以获取更多信息。应使用 === 运算符来测试此函数的返回值。

更新日志

版本 说明
8.0.0 encoding is nullable now.

参见

  • strrpos() - 计算指定字符串在目标字符串中最后一次出现的位置
  • iconv_strpos() - Finds position of first occurrence of a needle within a haystack
  • mb_strrpos() - 查找字符串在一个字符串中最后出现的位置

阅读全文 »

iconv 函数 iconv_substr 截取字符串的部分

发表日期:2021-07-01 08:55:46 | 来源: | 分类:iconv 函数

iconv_substr

(PHP 5, PHP 7, PHP 8)

iconv_substr截取字符串的部分

说明

iconv_substr(
    string $str,
    int $offset,
    int $length = iconv_strlen($str, $charset),
    string $charset = ini_get("iconv.internal_encoding")
): string

根据 offsetlength 参数指定 str 截取的部分。

参数

str

原始字符串。

offset

如果 offset 是非负数,iconv_substr()str 开头第 offset 个字符开始截出部分,从 0 开始计数。

如果 offset 是负数,iconv_substr()str 末尾向前 offset 个字符开始截取。

length

如果指定了 length 并且是正数,返回的值从 offset 截取部分,最多包含 length 个字符(取决于 string 的长度)。

如果传入了负数的 lengthiconv_substr() 将从第 offset 个字符到离末尾 length 个字符截出 str 的部分。 如果 offset 也是负数,则开始位置计算规则的解释见以上。

charset

如果省略了参数 charsetstring 的编码被认定为 iconv.internal_encoding。

注意,offsetlength 参数总是被认为字符表现的偏移,基于 charset 检测到的字符集进行统计计算,而相对应的 substr() 则是基于字节的位移来计算。

返回值

返回 offsetlength 参数指定的 str 的部分。

如果 stroffset 字符数更短,将会返回 false。 如果 stroffset 个字符的长度,将返回空字符串。

更新日志

版本 说明
7.0.11 如果 str 等长于 offset 个字符, 将返回空字符串。之前的版本里,这种情况是会返回 false 的。

参见

阅读全文 »

iconv 函数 iconv 字符串按要求的字符编码来转换

发表日期:2021-07-01 08:55:46 | 来源: | 分类:iconv 函数

      示例1
<?php 
$text = "This is the Euro symbol '€'.";
echo 'Original : ', $text, PHP_EOL;
echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL;
echo 'IGNORE   : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL;
echo 'Plain    : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL;
?>

阅读全文 »

iconv 函数 ob_iconv_handler 以输出缓冲处理程序转换字符编码

发表日期:2021-07-01 08:55:46 | 来源: | 分类:iconv 函数

      示例1
<?php 
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "ISO-8859-1");
ob_start("ob_iconv_handler");
 // 开始输出缓冲
 ?>

阅读全文 »

全部博文(1580)
集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。