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

字符串 函数 str_contains Determine if a string contains a given substring

发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数

      示例1
<?php 
if (str_contains('abc', '')) {
    echo "Checking the existence of the empty string will always return true";
}
?>

      示例2
<?php 
$string = 'The lazy fox jumped over the fence';
if (str_contains($string, 'lazy')) {
    echo "The string 'lazy' was found in the string\n";
}
if (str_contains($string, 'Lazy')) {
    echo 'The string "Lazy" was found in the string';
}
 else {
    echo '"Lazy" was not found because the case does not match';
}
?>

阅读全文 »

字符串 函数 str_pad 使用另一个字符串填充字符串为指定长度

发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数

      示例1
<?php 
$input = "Alien";
echo str_pad($input, 10);
                      // 输出 "Alien     "echo str_pad($input, 10, "-=", STR_PAD_LEFT);
  // 输出 "-=-=-Alien"echo str_pad($input, 10, "_", STR_PAD_BOTH);
   // 输出 "__Alien___"echo str_pad($input,  6, "___");
               // 输出 "Alien_"echo str_pad($input,  3, "*");
                 // 输出 "Alien"?>

阅读全文 »

字符串 函数 str_repeat 重复一个字符串

发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数

      示例1
<?php 
echo str_repeat("-=", 10);
?>

阅读全文 »

字符串 函数 str_replace 子字符串替换

发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数

      示例1
<?php 
// 赋值: <body text='black'>$bodytag = str_replace("%body%", "black", "<body text='%body%'>");
// 赋值: Hll Wrld f PHP$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
// 赋值: You should eat pizza, beer, and ice cream every day$phrase  = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy   = array("pizza", "beer", "ice cream");
$newphrase = str_replace($healthy, $yummy, $phrase);
// 赋值: 2$str = str_replace("ll", "", "good golly miss molly!", $count);
echo $count;
?>

      示例2
<?php 
// 替换顺序$str     = "Line 1\nLine 2\rLine 3\r\nLine 4\n";
$order   = array("\r\n", "\n", "\r");
$replace = '<br />';
// 首先替换 \r\n 字符,因此它们不会被两次转换$newstr = str_replace($order, $replace, $str);
// 输出 F ,因为 A 被 B 替换,B 又被 C 替换,以此类推...// 由于从左到右依次替换,最终 E 被 F 替换$search  = array('A', 'B', 'C', 'D', 'E');
$replace = array('B', 'C', 'D', 'E', 'F');
$subject = 'A';
echo str_replace($search, $replace, $subject);
// 输出: apearpearle pear// 由于上面提到的原因$letters = array('a', 'p');
$fruit   = array('apple', 'pear');
$text    = 'a p';
$output  = str_replace($letters, $fruit, $text);
echo $output;
?>

阅读全文 »

字符串 函数 str_rot13 对字符串执行 ROT13 转换

发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数

      示例1
<?php 
echo str_rot13('PHP 4.3.0');
 // CUC 4.3.0?>

阅读全文 »

字符串 函数 str_shuffle 随机打乱一个字符串

发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数

      示例1
<?php 
$str = 'abcdef';
$shuffled = str_shuffle($str);
// 输出类似于: bfdaececho $shuffled;
?>

阅读全文 »

字符串 函数 str_ireplace str_replace() 的忽略大小写版本

发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数

      示例1
<?php 
$bodytag = str_ireplace("%body%", "black", "<body text=%BODY%>");
echo $bodytag;
 // <body text=black>?>

阅读全文 »

字符串 函数 str_word_count 返回字符串中单词的使用情况

发表日期:2021-07-01 10:23:23 | 来源: | 分类:字符串 函数

      示例1
<?php 
$str = "Hello fri3nd, you're       looking          good today!";
print_r(str_word_count($str, 1));
print_r(str_word_count($str, 2));
print_r(str_word_count($str, 1, 'àáãç3'));
echo str_word_count($str);
?>

阅读全文 »

字符串 函数 md5 计算字符串的 MD5 散列值

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

      示例1
<?php 
$str = 'apple';
if (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {
    echo "Would you like a green or red apple?";
}
?>

阅读全文 »

字符串 函数 nl_langinfo Query language and locale information

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

nl_langinfo

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

nl_langinfoQuery language and locale information

说明

nl_langinfo(int $item): string|false

nl_langinfo() is used to access individual elements of the locale categories. Unlike localeconv(), which returns all of the elements, nl_langinfo() allows you to select any specific element.

参数

item

item may be an integer value of the element or the constant name of the element. The following is a list of constant names for item that may be used and their description. Some of these constants may not be defined or hold no value for certain locales.

nl_langinfo Constants
Constant Description
LC_TIME Category Constants
ABDAY_(1-7) Abbreviated name of n-th day of the week.
DAY_(1-7) Name of the n-th day of the week (DAY_1 = Sunday).
ABMON_(1-12) Abbreviated name of the n-th month of the year.
MON_(1-12) Name of the n-th month of the year.
AM_STR String for Ante meridian.
PM_STR String for Post meridian.
D_T_FMT String that can be used as the format string for strftime() to represent time and date.
D_FMT String that can be used as the format string for strftime() to represent date.
T_FMT String that can be used as the format string for strftime() to represent time.
T_FMT_AMPM String that can be used as the format string for strftime() to represent time in 12-hour format with ante/post meridian.
ERA Alternate era.
ERA_YEAR Year in alternate era format.
ERA_D_T_FMT Date and time in alternate era format (string can be used in strftime()).
ERA_D_FMT Date in alternate era format (string can be used in strftime()).
ERA_T_FMT Time in alternate era format (string can be used in strftime()).
LC_MONETARY Category Constants
INT_CURR_SYMBOL International currency symbol.
CURRENCY_SYMBOL Local currency symbol.
CRNCYSTR Same value as CURRENCY_SYMBOL.
MON_DECIMAL_POINT Decimal point character.
MON_THOUSANDS_SEP Thousands separator (groups of three digits).
MON_GROUPING Like "grouping" element.
POSITIVE_SIGN Sign for positive values.
NEGATIVE_SIGN Sign for negative values.
INT_FRAC_DIGITS International fractional digits.
FRAC_DIGITS Local fractional digits.
P_CS_PRECEDES Returns 1 if CURRENCY_SYMBOL precedes a positive value.
P_SEP_BY_SPACE Returns 1 if a space separates CURRENCY_SYMBOL from a positive value.
N_CS_PRECEDES Returns 1 if CURRENCY_SYMBOL precedes a negative value.
N_SEP_BY_SPACE Returns 1 if a space separates CURRENCY_SYMBOL from a negative value.
P_SIGN_POSN
  • Returns 0 if parentheses surround the quantity and CURRENCY_SYMBOL.
  • Returns 1 if the sign string precedes the quantity and CURRENCY_SYMBOL.
  • Returns 2 if the sign string follows the quantity and CURRENCY_SYMBOL.
  • Returns 3 if the sign string immediately precedes the CURRENCY_SYMBOL.
  • Returns 4 if the sign string immediately follows the CURRENCY_SYMBOL.
N_SIGN_POSN
LC_NUMERIC Category Constants
DECIMAL_POINT Decimal point character.
RADIXCHAR Same value as DECIMAL_POINT.
THOUSANDS_SEP Separator character for thousands (groups of three digits).
THOUSEP Same value as THOUSANDS_SEP.
GROUPING  
LC_MESSAGES Category Constants
YESEXPR Regex string for matching "yes" input.
NOEXPR Regex string for matching "no" input.
YESSTR Output string for "yes".
NOSTR Output string for "no".
LC_CTYPE Category Constants
CODESET Return a string with the name of the character encoding.

返回值

Returns the element as a string, or false if item is not valid.

注释

注意: 此函数未在 Windows 平台下实现。

参见

阅读全文 »

字符串 函数 metaphone Calculate the metaphone key of a string

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

      示例1
<?php 
var_dump(metaphone('programming'));
var_dump(metaphone('programmer'));
?>

      示例2
<?php 
var_dump(metaphone('programming', 5));
var_dump(metaphone('programmer', 5));
?>

      示例3
<?php 
var_dump(metaphone('Asterix', 5));
?>

阅读全文 »

字符串 函数 money_format 将数字格式化成货币字符串

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

      示例1
<?php 
$number = 1234.56;
// 让我们打印 en_US locale 的国际化格式setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "\n";
// USD 1,234.56// 意大利国家的格式,带两位浮点小数`setlocale(LC_MONETARY, 'it_IT');
echo money_format('%.2n', $number) . "\n";
// Eu 1.234,56// 负数的使用$number = -1234.5672;
// 美国国家的格式,使用圆括号 () 标记负数。// 左侧精度使用十位setlocale(LC_MONETARY, 'en_US');
echo money_format('%(#10n', $number) . "\n";
// ($        1,234.57)// 相似的格式,添加了右侧两位小数点的精度,同时用 * 来填充echo money_format('%=*(#10.2n', $number) . "\n";
// ($********1,234.57)// 让我们左对齐,14位宽,左侧八位,右侧两位,不带分组字符// de_DE 的国际化格式setlocale(LC_MONETARY, 'de_DE');
echo money_format('%=*^-14#8.2i', 1234.56) . "\n";
// Eu 1234,56****/
/ 让我们在格式字符串前后,添加一些简介setlocale(LC_MONETARY, 'en_GB');
$fmt = 'The final value is %i (after a 10%% discount)';
echo money_format($fmt, 1234.56) . "\n";
// The final value is  GBP 1,234.56 (after a 10% discount)?>

阅读全文 »

字符串 函数 localeconv Get numeric formatting information

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

      示例1
<?php 
if (false !== setlocale(LC_ALL, 'nl_NL.UTF-8@euro')) {
    $locale_info = localeconv();
    print_r($locale_info);
}
?>

阅读全文 »

字符串 函数 number_format 以千位分隔符方式格式化一个数字

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

      示例1
<?php 
$number = 1234.56;
// english notation (default)$english_format_number = number_format($number);
// 1,235// French notation$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56$number = 1234.5678;
// english notation without thousands separator$english_format_number = number_format($number, 2, '.', '');
// 1234.57?>

阅读全文 »

字符串 函数 nl2br 在字符串所有新行之前插入 HTML 换行标记

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

      示例1
<?php 
echo nl2br("foo isn't\n bar");
?>

      示例2
<?php 
echo nl2br("Welcome\r\nThis is my HTML document", false);
?>

      示例3
<?php 
$string = "This\r\nis\n\ra\nstring\r";
echo nl2br($string);
?>

阅读全文 »

字符串 函数 print 输出字符串

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

      示例1
<?php 
print("Hello World");
print "print() also works without parentheses.";
print "This spansmultiple lines. The newlines will beoutput as well";
print "This spans\nmultiple lines. The newlines will be\noutput as well.";
print "escaping characters is done \"Like this\".";
// 可以在打印语句中使用变量$foo = "foobar";
$bar = "barbaz";
print "foo is $foo";
 // foo is foobar// 也可以使用数组$bar = array("value" => "foo");
print "this is {
$bar['value']}
 !";
 // this is foo !// 使用单引号将打印变量名,而不是变量的值print 'foo is $foo';
 // foo is $foo// 如果没有使用任何其他字符,可以仅打印变量print $foo;
          // foobarprint <<<ENDThis uses the "here document" syntax to outputmultiple lines with $variable interpolation. Notethat the here document terminator must appear on aline with just a semicolon no extra whitespace!END;
?>

阅读全文 »

字符串 函数 quoted_printable_decode 将 quoted-printable 字符串转换为 8-bit 字符串

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

quoted_printable_decode

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

quoted_printable_decode将 quoted-printable 字符串转换为 8-bit 字符串

说明

quoted_printable_decode(string $str): string

该函数返回 quoted-printable 解码之后的 8-bit 字符串 (参考 » RFC2045 的6.7章节,而不是 » RFC2821 的4.5.2章节,so additional periods are not stripped from the beginning of line)

该函数与 imap_qprint() 函数十分相似,但是该函数不需要依赖 IMAP 模块。

参数

str

输入的字符串。

返回值

返回的 8-bit 二进制字符串。

参见

阅读全文 »

字符串 函数 ord 转换字符串第一个字节为 0-255 之间的值

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

      示例1
<?php 
$str = "\n";
if (ord($str) == 10) {
    echo "The first character of \$str is a line feed.\n";
}
?>

      示例2
<?php 
declare(encoding='UTF-8');
$str = "22";
for ( $pos=0;
 $pos < strlen($str);
 $pos ++ ) {
 $byte = substr($str, $pos);
 echo 'Byte ' . $pos . ' of $str has value ' . ord($byte) . PHP_EOL;
}
?>

阅读全文 »

字符串 函数 printf 输出格式化字符串

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

printf

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

printf输出格式化字符串

说明

printf(string $format, mixed $args = ?, mixed $... = ?): int

依据 format 格式参数产生输出。

参数

format

format 描述信息,请参见 sprintf()

args

...

返回值

返回输出字符串的长度。

参见

阅读全文 »

字符串 函数 quotemeta 转义元字符集

发表日期:2021-07-01 10:23:22 | 来源: | 分类:字符串 函数

quotemeta

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

quotemeta转义元字符集

说明

quotemeta(string $str): string

返回 在下面这些特殊字符前加 反斜线(\) 转义后的字符串。 这些特殊字符包含:

. \ + * ? [ ^ ] ( $ )

参数

str

输入字符串

返回值

返回 元字符集被转义后的 字符串,如果输入字符串str为空, 则返回 false

注释

注意: 此函数可安全用于二进制对象。

参见

  • addslashes() - 使用反斜线引用字符串
  • addcslashes() - 以 C 语言风格使用反斜线转义字符串中的字符
  • htmlentities() - 将字符转换为 HTML 转义字符
  • htmlspecialchars() - 将特殊字符转换为 HTML 实体
  • nl2br() - 在字符串所有新行之前插入 HTML 换行标记
  • stripslashes() - 反引用一个引用字符串
  • stripcslashes() - 反引用一个使用 addcslashes 转义的字符串
  • ereg()
  • preg_quote() - 转义正则表达式字符

阅读全文 »

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