字符串 函数 业 ,精于勤 荒于嬉.

字符串 函数 addcslashes 以 C 语言风格使用反斜线转义字符串中的字符

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

      示例1
1<?php 
2echo addcslashes('foo[ ]''A..z');
3// 输出:\f\o\o\[ \]
      示例2
1// 所有大小写字母均被转义
      示例3
1// ... 但 [\]^_` 以及分隔符、换行符、回车符等也一并被转义了。
      示例4
      示例5
1<?php 
2echo addcslashes("zoo['.']"'z..A');
3// 输出:\zoo['\.']
      示例6
      示例7
1<?php 
2$escaped addcslashes($not_escaped"\0..\37!@\177..\377");
3?>

阅读全文 »

字符串 函数 addslashes 使用反斜线引用字符串

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

      示例1
1<?php 
2$str "Is your name O'reilly?";
3// 输出: Is your name O\'reilly?
4echo addslashes($str);
5?>

阅读全文 »

字符串 函数 bin2hex 函数把包含数据的二进制字符串转换为十六进制值

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

bin2hex

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

bin2hex函数把包含数据的二进制字符串转换为十六进制值

说明

bin2hex(string $str): string

把二进制的参数 str 转换为的十六进制的字符串。转换使用字节方式,高四位字节优先。

参数

str

二进制字符串。

返回值

返回指定字符串十六进制的表示。

参见

  • hex2bin() - 转换十六进制字符串为二进制字符串
  • pack() - 将数据打包成二进制字符串

阅读全文 »

字符串 函数 chop rtrim() 的别名

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

chop

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

choprtrim() 的别名

说明

此函数是该函数的别名:rtrim()

注释

注意:

chop() 与 Perl 的 chop() 函数有所不同,它会删除字符串的最后一个字符。

阅读全文 »

字符串 函数 chr 返回指定的字符

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

      示例1
1<?php
2$str "The string ends in escape: ";
3$str .= chr(27);
4 /* 在 $str 后边增加换码符 */
5/* 通常这样更有用 */
6$str = sprintf("The string ends in escape: %c", 27);
7?>

阅读全文 »

字符串 函数 chunk_split 将字符串分割成小块

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

      示例1
1<?php
2// 使用 RFC 2045 语义格式化 $data$new_string = chunk_split(base64_encode($data));
3?>

阅读全文 »

字符串 函数 convert_cyr_string 将字符由一种 Cyrillic 字符转换成另一种

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

convert_cyr_string

(PHP 4, PHP 5, PHP 7)

convert_cyr_string将字符由一种 Cyrillic 字符转换成另一种

说明

convert_cyr_string(string $str, string $from, string $to): string

此函数将给定的字符串从一种 Cyrillic 字符转换成另一种,返回转换之后的字符串。

参数

str

要转换的字符。

from

单个字符,代表源 Cyrillic 字符集。

to

单个字符,代表了目标 Cyrillic 字符集。

支持的类型有:

  • k - koi8-r
  • w - windows-1251
  • i - iso8859-5
  • a - x-cp866
  • d - x-cp866
  • m - x-mac-cyrillic

返回值

返回转换后的字符串。

注释

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

阅读全文 »

字符串 函数 convert_uudecode 解码一个 uuencode 编码的字符串

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

      示例1
1<?php
2/* 你猜会输出啥?:) */
3echo convert_uudecode("+22!L;
4W9E(%!(4\"$`\n`");
5?>

阅读全文 »

字符串 函数 convert_uuencode 使用 uuencode 编码一个字符串

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

      示例1
1<?php
2$some_string "test\ntext text\r\n";
3echo convert_uuencode($some_string);
4?>

阅读全文 »

字符串 函数 count_chars 返回字符串所用字符的信息

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

      示例1
1<?php
2$data "Two Ts and one F.";
3foreach (count_chars($data, 1) as $i => $val) {
4   echo "There were $val instance(s) of \"" chr($i) , "\" in the string.\n";
5}
6?>

阅读全文 »

字符串 函数 crc32 计算一个字符串的 crc32 多项式

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

      示例1
1<?php
2$checksum = crc32("The quick brown fox jumped over the lazy dog.");
3printf("%u\n"$checksum);
4?>

阅读全文 »

字符串 函数 crypt 单向字符串散列

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

      示例1
1<?php
2$hashed_password = crypt('mypassword');
3 // 自动生成盐值/* 你应当使用 crypt() 得到的完整结果作为盐值进行密码校验,以此来避免使用不同散列算法导致的问题。(如上所述,基于标准 DES 算法的密码散列使用 2 字符盐值,但是基于 MD5 算法的散列使用 12 个字符盐值。)*/
4if (hash_equals($hashed_password, crypt($user_input$hashed_password))) {
5   echo "Password verified!";
6}
7?>
      示例2
1<?php
2// 设置密码$password = 'mypassword';
3// 获取散列值,使用自动盐值$hash = crypt($password);
4?>
      示例3
01<?php
02if (CRYPT_STD_DES == 1) {
03    echo 'Standard DES: ' . crypt('rasmuslerdorf''rl') . "\n";
04}
05if (CRYPT_EXT_DES == 1) {
06    echo 'Extended DES: ' . crypt('rasmuslerdorf''_J9..rasm') . "\n";
07}
08if (CRYPT_MD5 == 1) {
09    echo 'MD5:          ' . crypt('rasmuslerdorf''$1$rasmusle$') . "\n";
10}
11if (CRYPT_BLOWFISH == 1) {
12    echo 'Blowfish:     ' . crypt('rasmuslerdorf''$2a$07$usesomesillystringforsalt$') . "\n";
13}
14if (CRYPT_SHA256 == 1) {
15    echo 'SHA-256:      ' . crypt('rasmuslerdorf''$5$rounds=5000$usesomesillystringforsalt$') . "\n";
16}
17if (CRYPT_SHA512 == 1) {
18    echo 'SHA-512:      ' . crypt('rasmuslerdorf''$6$rounds=5000$usesomesillystringforsalt$') . "\n";
19}
20?>

阅读全文 »

字符串 函数 echo 输出一个或多个字符串

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

      示例1
1I have <?=$foo?> foo.
      示例2
1<?php
2echo "Hello World";
3// Strings can either be passed individually as multiple arguments or// concatenated together and passed as a single argumentecho 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10);
4echo 'This ' 'string ' 'was ' 'made ' 'with concatenation.' "\n";
5// Because echo does not behave like a function, the following code is invalid.($some_var) ? echo 'true' : echo 'false';
6// However, the following examples will work:($some_var) ? print 'true' : print 'false';
7 // print is also a construct, but                                            // it behaves like a function, so                                            // it may be used in this context.echo $some_var ? 'true': 'false';
8 // changing the statement around?>
      示例3
1<?php
2echo "Sum: ", 1 + 2;
3echo "Hello ", isset($name) ? $name "John Doe""!";
      示例4
1<?php
2echo 'Sum: ' . (1 + 2);
3echo 'Hello ' . (isset($name) ? $name 'John Doe') . '!';

阅读全文 »

字符串 函数 explode 使用一个字符串分割另一个字符串

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

      示例1
01<?php
02// 示例 1$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
03$pieces explode(" "$pizza);
04echo $pieces[0];
05 // piece1echo $pieces[1];
06 // piece2// 示例 2$data = "foo:*:1023:1000::/home/foo:/bin/sh";
07list($user$pass$uid$gid$gecos$home$shell) = explode(":"$data);
08echo $user;
09 // fooecho $pass;
10 // *?>
      示例2
1<?php
2/*  字符串内不包含分隔字符时,  会简单返回只有一个原始字符串元素的 array。*/
3$input1 "hello";
4$input2 "hello,there";
5$input3 ',';
6var_dump( explode','$input1 ) );
7var_dump( explode','$input2 ) );
8var_dump( explode','$input3 ) );
9?>
      示例3
1<?php
2$str 'one|two|three|four';
3// 正数的 limitprint_r(explode('|', $str, 2));
4// 负数的 limitprint_r(explode('|', $str, -1));
5?>

阅读全文 »

字符串 函数 fprintf 将格式化后的字符串写入到流

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

      示例1
1<?php
2if (!($fp fopen('date.txt''w'))) {
3    return;
4}
5fprintf($fp"%04d-%02d-%02d"$year$month$day);
6// will write the formatted ISO date to date.txt?>
      示例2
01<?php
02if (!($fp fopen('currency.txt''w'))) {
03    return;
04}
05$money1 = 68.75;
06$money2 = 54.35;
07$money $money1 $money2;
08// echo $money will output "123.1";
09$len fprintf($fp'%01.2f'$money);
10// will write "123.10" to currency.txtecho "wrote $len bytes to currency.txt";
11// use the return value of fprintf to determine how many bytes we wrote?>

阅读全文 »

字符串 函数 get_html_translation_table 返回使用 htmlspecialchars() 和 htmlentities() 后的转换表

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

      示例1
1<?php
2var_dump(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES | ENT_HTML5));
3?>

阅读全文 »

字符串 函数 hebrev 将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew)

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

hebrev

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

hebrev将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew)

说明

hebrev(string $hebrew_text, int $max_chars_per_line = 0): string

将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew)

函数将会尝试避免破坏单词。

参数

hebrew_text

逻辑顺序希伯来文字符串。

max_chars_per_line

可选参数,表示每行可返回的最多字符数。

返回值

返回视觉顺序字符串。

参见

  • hebrevc() - 将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew),并且转换换行符

阅读全文 »

字符串 函数 hebrevc 将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew),并且转换换行符

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

hebrevc

(PHP 4, PHP 5, PHP 7)

hebrevc将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew),并且转换换行符

说明

hebrevc(string $hebrew_text, int $max_chars_per_line = 0): string

本函数与hebrev() 一样,唯一的区别是 本函数会额外将换行符(\n)转换为"<br>\n"。

函数将会尝试避免破坏单词。

参数

hebrew_text

逻辑顺序希伯来文字符串。

max_chars_per_line

可选参数,表示每行可返回的最多字符数。

返回值

返回视觉顺序字符串。

参见

  • hebrev() - 将逻辑顺序希伯来文(logical-Hebrew)转换为视觉顺序希伯来文(visual-Hebrew)

阅读全文 »

字符串 函数 hex2bin 转换十六进制字符串为二进制字符串

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

      示例1
1<?php
2$hex = hex2bin("6578616d706c65206865782064617461");
3var_dump($hex);
4?>

阅读全文 »

字符串 函数 html_entity_decode Convert HTML entities to their corresponding characters

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

      示例1
01<?php
02$orig "I'll \"walk\" the <b>dog</b> now";
03$a = htmlentities($orig);
04$b = html_entity_decode($a);
05echo $a;
06 // I'll &quot;
07walk&quot;
08 the &lt;
09b&gt;
10dog&lt;
11/b&gt;
12 nowecho $b;
13 // I'll "walk" the <b>dog</b> now?>

阅读全文 »

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