无需言 做自己 业 ,精于勤 荒于嬉.

GD 和图像处理 函数 imagecolorclosest 取得与指定的颜色最接近的颜色的索引值

发表日期:2021-07-01 08:55:56 | 来源: | 分类:GD 和图像处理 函数

imagecolorclosest

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecolorclosest取得与指定的颜色最接近的颜色的索引值

说明

imagecolorclosest(
    resource $image,
    int $red,
    int $green,
    int $blue
): int

返回图像调色板中与指定的 RGB 值最“接近”的颜色。

指定的颜色与调色板中的每个颜色的“距离”的计算方法是把 RGB 值当成三维空间中点的坐标。

如果从文件创建了图像,只有图像中使用了的颜色会被辨析。仅出现在调色板中的颜色不会被辨析。

参见 imagecolorexact()

阅读全文 »

GD 和图像处理 函数 gd_info 取得当前安装的 GD 库的信息

发表日期:2021-07-01 08:55:55 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
var_dump(gd_info());
?>

阅读全文 »

GD 和图像处理 函数 image_type_to_extension 取得图像类型的文件后缀

发表日期:2021-07-01 08:55:55 | 来源: | 分类:GD 和图像处理 函数

      示例1
<?php 
// 创建图像实例$im = imagecreatetruecolor(100, 100);
// 保存图像imagepng($im, './test' . image_type_to_extension(IMAGETYPE_PNG));
imagedestroy($im);
?>

阅读全文 »

多字节字符串 函数 mb_substitute_character 设置/获取替代字符

发表日期:2021-07-01 08:55:54 | 来源: | 分类:多字节字符串 函数

      示例1
<?php 
/* 设置为 Unicode U+3013 (GETA MARK) */
mb_substitute_character(0x3013);
/* 设置十六进制格式 */
mb_substitute_character("long");
/* 显示当前设置 */
echo mb_substitute_character();
?>

阅读全文 »

多字节字符串 函数 mb_strwidth 返回字符串的宽度

发表日期:2021-07-01 08:55:54 | 来源: | 分类:多字节字符串 函数

mb_strwidth

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_strwidth返回字符串的宽度

说明

mb_strwidth(string $str, string $encoding = mb_internal_encoding()): int

返回 string 类型 str 的宽度。

多字节字符通常是单字节字符的两倍宽度。

字符宽度
字符 宽度
U+0000 - U+0019 0
U+0020 - U+1FFF 1
U+2000 - U+FF60 2
U+FF61 - U+FF9F 1
U+FFA0 - 2

参数

str

待解码的 string

encoding

encoding 参数为字符编码。如果省略或是 null,则使用内部字符编码。

返回值

string str 的宽度。

参见

阅读全文 »

多字节字符串 函数 mb_substr_count 统计字符串出现的次数

发表日期:2021-07-01 08:55:54 | 来源: | 分类:多字节字符串 函数

      示例1
<?php 
echo mb_substr_count("This is a test", "is");
 // 输出 2?>

阅读全文 »

多字节字符串 函数 mb_strtoupper 使字符串大写

发表日期:2021-07-01 08:55:54 | 来源: | 分类:多字节字符串 函数

      示例1
<?php 
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = mb_strtoupper($str);
echo $str;
 // Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO?>

      示例2
<?php 
$str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός";
$str = mb_strtoupper($str, 'UTF-8');
echo $str;
 // 打印了 ΤΆΧΙΣΤΗ ΑΛΏΠΗΞ ΒΑΦΉΣ ΨΗΜΈΝΗ ΓΗ, ΔΡΑΣΚΕΛΊΖΕΙ ΥΠΈΡ ΝΩΘΡΟΎ ΚΥΝΌΣ?>

阅读全文 »

多字节字符串 函数 mb_strrchr 查找指定字符在另一个字符串中最后一次的出现

发表日期:2021-07-01 08:55:54 | 来源: | 分类:多字节字符串 函数

mb_strrchr

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

mb_strrchr查找指定字符在另一个字符串中最后一次的出现

说明

mb_strrchr(
    string $haystack,
    string $needle,
    bool $part = false,
    string $encoding = mb_internal_encoding()
): string

mb_strrchr() 查找了 needlehaystack 中最后一次出现的位置,并返回 haystack 的部分。 如果没有找到 needle,它将返回 false

参数

haystack

在该字符串中查找 needle 最后出现的位置

needle

haystack 中查找这个字符串

part

决定这个函数返回 haystack 的哪一部分。 如果设置为 true,它将返回的字符是从 haystack 的开始到 needle 最后出现的位置。 如果设置为 false,它将返回的字符是从 needle 最后出现的位置到 haystack 的末尾。

encoding

使用的字符编码名称。如果省略了,则将使用内部编码。

返回值

返回 haystack 的一部分。 或者在没有找到 needle 时返回 false

参见

  • strrchr() - 查找指定字符在字符串中的最后一次出现
  • mb_strstr() - 查找字符串在另一个字符串里的首次出现
  • mb_strrichr() - 大小写不敏感地查找指定字符在另一个字符串中最后一次的出现

阅读全文 »

多字节字符串 函数 mb_substr 获取部分字符串

发表日期:2021-07-01 08:55:54 | 来源: | 分类:多字节字符串 函数

mb_substr

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_substr获取部分字符串

说明

mb_substr(
    string $str,
    int $start,
    int $length = NULL,
    string $encoding = mb_internal_encoding()
): string

根据字符数执行一个多字节安全的 substr() 操作。 位置是从 str 的开始位置进行计数。 第一个字符的位置是 0。第二个字符的位置是 1,以此类推。

参数

str

从该 string 中提取子字符串。

start

如果 start 不是负数,返回的字符串会从 strstart 的位置开始,从 0 开始计数。举个例子,字符串 'abcdef',位置 0 的字符是 'a',位置 2 的字符是 'c',以此类推。

如果 start 是负数,返回的字符串是从 str 末尾处第 start 个字符开始的。

length

str 中要使用的最大字符数。如果省略了此参数或者传入了 NULL,则会提取到字符串的尾部。

encoding

encoding 参数为字符编码。如果省略或是 null,则使用内部字符编码。

返回值

mb_substr() 函数根据 startlength 参数返回 str 中指定的部分。

更新日志

版本 说明
5.4.8 length 传入 NULL,则从 start 提取到字符串的结尾处。 在之前的版本里, NULL 会被当作 0 来处理。

参见

阅读全文 »

多字节字符串 函数 mb_regex_set_options Set/Get the default options for mbregex functions

发表日期:2021-07-01 08:55:53 | 来源: | 分类:多字节字符串 函数

mb_regex_set_options

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

mb_regex_set_optionsSet/Get the default options for mbregex functions

说明

mb_regex_set_options(string|null $options = null): string

Sets the default options described by options for multibyte regex functions.

参数

options

The options to set. This is a string where each character is an option. To set a mode, the mode character must be the last one set, however there can only be set one mode but multiple options.

Regex options
Option Meaning
i Ambiguity match on
x Enables extended pattern form
m '.' matches with newlines
s '^' -> '\A', '$' -> '\Z'
p Same as both the m and s options
l Finds longest matches
n Ignores empty matches
e eval() resulting code
Regex syntax modes
Mode Meaning
j Java (Sun java.util.regex)
u GNU regex
g grep
c Emacs
r Ruby
z Perl
b POSIX Basic regex
d POSIX Extended regex

返回值

The previous options. If options is omitted or null, it returns the string that describes the current options.

更新日志

版本 说明
8.0.0 If the parameter options is given and not null, the previous options are returned. Formerly, the current options have been returned.
8.0.0 options is nullable now.

参见

  • mb_split() - 使用正则表达式分割多字节字符串
  • mb_ereg() - Regular expression match with multibyte support
  • mb_eregi() - Regular expression match ignoring case with multibyte support

阅读全文 »

多字节字符串 函数 mb_regex_encoding Set/Get character encoding for multibyte regex

发表日期:2021-07-01 08:55:53 | 来源: | 分类:多字节字符串 函数

mb_regex_encoding

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

mb_regex_encodingSet/Get character encoding for multibyte regex

说明

mb_regex_encoding(string|null $encoding = null): string|bool

Set/Get character encoding for a multibyte regex.

参数

encoding

encoding 参数为字符编码。如果省略或是 null,则使用内部字符编码。

返回值

If encoding is set, then 成功时返回 true, 或者在失败时返回 false。 In this case, the internal character encoding is NOT changed. If encoding is omitted, then the current character encoding name for a multibyte regex is returned.

更新日志

版本 说明
8.0.0 现在 encoding 可以为 null。

参见

阅读全文 »

多字节字符串 函数 mb_send_mail 发送编码过的邮件

发表日期:2021-07-01 08:55:53 | 来源: | 分类:多字节字符串 函数

mb_send_mail

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_send_mail发送编码过的邮件

说明

mb_send_mail(
    string $to,
    string $subject,
    string $message,
    string $additional_headers = null,
    string $additional_parameter = null
): bool

发送邮件。邮件头和内容根据 mb_language() 设置来转换编码。 这是 mail() 的一个包装器函数,所以详情参见 mail()

参数

to

被发送到该邮件地址。可通过逗号分隔地址的 to 来指定多个收件人。 该参数不会被自动编码。

subject

邮件标题。

message

邮件消息。

additional_headers(可选)

String to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). Validate parameter not to be injected unwanted headers by attackers.

注意:

When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.

Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.

注意:

If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents (most notably » qmail) replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822.

additional_parameter

additional_parameter 是一个 MTA 命令行参数。 在使用 sendmail 时对设置正确的返回路径头很有帮助。

This parameter is escaped by escapeshellcmd() internally to prevent command execution. escapeshellcmd() prevents command execution, but allows to add addtional parameters. For security reason, this parameter should be validated.

Since escapeshellcmd() is applied automatically, some characters that are allowed as email addresses by internet RFCs cannot be used. Programs that are required to use these characters mail() cannot be used.

The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is /etc/mail/trusted-users.

返回值

成功时返回 true, 或者在失败时返回 false

参见

阅读全文 »

多字节字符串 函数 mb_split 使用正则表达式分割多字节字符串

发表日期:2021-07-01 08:55:53 | 来源: | 分类:多字节字符串 函数

mb_split

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

mb_split使用正则表达式分割多字节字符串

说明

mb_split(string $pattern, string $string, int $limit = -1): array

使用正则表达式 pattern 分割多字节 string 并返回结果 array

参数

pattern

正则表达式。

string

待分割的 string

limit
如果指定了可选参数 limit,将最多分割为 limit 个元素。

返回值

array 的结果。

注释

注意:

The character encoding specified by mb_regex_encoding() will be used as the character encoding for this function by default.

参见

阅读全文 »

多字节字符串 函数 mb_str_split Given a multibyte string, return an array of its characters

发表日期:2021-07-01 08:55:53 | 来源: | 分类:多字节字符串 函数

mb_str_split

(PHP 7 >= 7.4.0, PHP 8)

mb_str_splitGiven a multibyte string, return an array of its characters

说明

mb_str_split(string $string, int $length = 1, string|null $encoding = null): array

This function will return an array of strings, it is a version of str_split() with support for encodings of variable character size as well as fixed-size encodings of 1,2 or 4 byte characters. If the length parameter is specified, the string is broken down into chunks of the specified length in characters (not bytes). The encoding parameter can be optionally specified and it is good practice to do so.

参数

string

The string to split into characters or chunks.

length

If specified, each element of the returned array will be composed of multiple characters instead of a single character.

encoding

encoding 参数为字符编码。如果省略或是 null,则使用内部字符编码。

A string specifying one of the supported encodings.

返回值

mb_str_split() returns an array of strings.

更新日志

版本 说明
8.0.0 现在 encoding 可以为 null。
8.0.0 This function no longer returns false on failure.

参见

阅读全文 »

多字节字符串 函数 mb_stripos 大小写不敏感地查找字符串在另一个字符串中首次出现的位置

发表日期:2021-07-01 08:55:53 | 来源: | 分类:多字节字符串 函数

mb_stripos

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

mb_stripos大小写不敏感地查找字符串在另一个字符串中首次出现的位置

说明

mb_stripos(
    string $haystack,
    string $needle,
    int $offset = 0,
    string $encoding = mb_internal_encoding()
): int

mb_stripos() 返回 needle 在字符串 haystack 中首次出现位置的数值。 和 mb_strpos() 不同的是,mb_stripos() 是大小写不敏感的。 如果 needle 没找到,它将返回 false

参数

haystack

在这个字符串中查找获取 needle 首次出现的位置

needle

haystack 中查找这个字符串

offset

haystack 里开始搜索的位置。如果是负数,就从字符串的尾部开始统计。

encoding

使用的字符编码名称。 如果省略了它,将使用内部字符编码。

返回值

返回字符串 haystackneedle 首次出现位置的数值。 如果没有找到 needle,它将返回 false

更新日志

版本 说明
7.1.0 支持 offset 使用负数。

参见

  • stripos() - 查找字符串首次出现的位置(不区分大小写)
  • strpos() - 查找字符串首次出现的位置
  • mb_strpos() - 查找字符串在另一个字符串中首次出现的位置

阅读全文 »

多字节字符串 函数 mb_strimwidth 获取按指定宽度截断的字符串

发表日期:2021-07-01 08:55:53 | 来源: | 分类:多字节字符串 函数

      示例1
<?php 
echo mb_strimwidth("Hello World", 0, 10, "...");
// 输出 Hello W...?>

阅读全文 »

多字节字符串 函数 mb_strcut 获取字符的一部分

发表日期:2021-07-01 08:55:53 | 来源: | 分类:多字节字符串 函数

mb_strcut

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_strcut获取字符的一部分

说明

mb_strcut(
    string $str,
    int $start,
    int $length = NULL,
    string $encoding = mb_internal_encoding()
): string

mb_strcut()mb_substr() 类似,都是从字符串中提取子字符串,但是按字节数来执行,而不是字符个数。 如果截断位置位于多字节字符两个字节的中间,将于该字符的第一个字节开始执行。 这也是和 substr() 函数的不同之处,后者简单地将字符串在字节之间截断,这将导致一个畸形的字节序列。

参数

str

要截断的 string

start

如果 start 不是负数,返回的字符串会从 str 的第 start 字节位置开始,从 0 开始计数。举个例子,字符串 'abcdef',字节位置 0 的字符是 'a',字节位置 2 的字符是 'c',以此类推。

如果 start 是负数,返回的字符串是从 str 末尾处第 start 个字节开始的。

length

字节长度。If omitted or NULL is passed, extract all bytes to the end of the string.

encoding

encoding 参数为字符编码。如果省略或是 null,则使用内部字符编码。

返回值

mb_strcut() 根据 startlength 参数返回 str 的一部分。

更新日志

版本 说明
5.4.8 Passing NULL as length extracts all bytes to the end of the string. Prior to this version NULL was treated the same as 0.

参见

阅读全文 »

多字节字符串 函数 mb_strlen 获取字符串的长度

发表日期:2021-07-01 08:55:53 | 来源: | 分类:多字节字符串 函数

mb_strlen

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_strlen获取字符串的长度

说明

mb_strlen(string $str, string $encoding = mb_internal_encoding()): mixed

获取一个 string 的长度。

参数

str

要检查长度的字符串

encoding

encoding 参数为字符编码。如果省略或是 null,则使用内部字符编码。

返回值

返回具有 encoding 编码的字符串 str 包含的字符数。 多字节的字符被计为 1。

如果给定的 encoding 无效则返回 false

参见

阅读全文 »

多字节字符串 函数 mb_strrichr 大小写不敏感地查找指定字符在另一个字符串中最后一次的出现

发表日期:2021-07-01 08:55:53 | 来源: | 分类:多字节字符串 函数

mb_strrichr

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

mb_strrichr大小写不敏感地查找指定字符在另一个字符串中最后一次的出现

说明

mb_strrichr(
    string $haystack,
    string $needle,
    bool $part = false,
    string $encoding = mb_internal_encoding()
): string

mb_strrichr() 大小写不敏感地查找指定 needlehaystack 中最后一次的出现,并返回 haystack 的一部分。 和 mb_strrchr() 不同的是,mb_strrichr() 是大小写不敏感的。 如果 needle 没有找到,它将返回 false

参数

haystack

在该字符串中查找 needle 的最后出现位置

needle

needle 中查找该字符串

part

决定这个函数返回 haystack 的哪一部分。 如果设置为 true,它将返回的字符是从 haystack 的开始到 needle 最后出现的位置。 如果设置为 false,它将返回的字符是从 needle 最后出现的位置到 haystack 的末尾。

encoding

使用的字符编码名称。如果省略了,则将使用内部编码。

返回值

返回 haystack 的一部分。 或者在没有找到 needle 时返回 false

参见

  • mb_stristr() - 大小写不敏感地查找字符串在另一个字符串里的首次出现
  • mb_strrchr() - 查找指定字符在另一个字符串中最后一次的出现

阅读全文 »

多字节字符串 函数 mb_strpos 查找字符串在另一个字符串中首次出现的位置

发表日期:2021-07-01 08:55:53 | 来源: | 分类:多字节字符串 函数

mb_strpos

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_strpos查找字符串在另一个字符串中首次出现的位置

说明

mb_strpos(
    string $haystack,
    string $needle,
    int $offset = 0,
    string $encoding = mb_internal_encoding()
): int

查找 string 在一个 string 中首次出现的位置。

基于字符数执行一个多字节安全的 strpos() 操作。 第一个字符的位置是 0,第二个字符的位置是 1,以此类推。

参数

haystack

要被检查的 string

needle

haystack 中查找这个字符串。 和 strpos() 不同的是,数字的值不会被当做字符的顺序值。

offset

搜索位置的偏移。如果没有提供该参数,将会使用 0。负数的 offset 会从字符串尾部开始统计。

encoding

encoding 参数为字符编码。如果省略或是 null,则使用内部字符编码。

返回值

返回 stringhaystackneedle 首次出现位置的数值。 如果没有找到 needle,它将返回 false

更新日志

版本 说明
7.1.0 支持负数的 offset

参见

阅读全文 »

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