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

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

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

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

阅读全文 »

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

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

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

阅读全文 »

字符串 函数 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() - 将数据打包成二进制字符串

阅读全文 »

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

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

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

阅读全文 »

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

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

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

阅读全文 »

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

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

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

阅读全文 »

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

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

chop

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

choprtrim() 的别名

说明

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

注释

注意:

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

阅读全文 »

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

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

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

阅读全文 »

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

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

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

阅读全文 »

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

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

      示例1
I have <?=$foo?> foo.
      示例2
<?php 
echo "Hello World";
// 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);
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n";
// Because echo does not behave like a function, the following code is invalid.($some_var) ? echo 'true' : echo 'false';
// However, the following examples will work:($some_var) ? print 'true' : print 'false';
 // print is also a construct, but                                            // it behaves like a function, so                                            // it may be used in this context.echo $some_var ? 'true': 'false';
 // changing the statement around?>

      示例3
<?php 
echo "Sum: ", 1 + 2;
echo "Hello ", isset($name) ? $name : "John Doe", "!";


      示例4
<?php 
echo 'Sum: ' . (1 + 2);
echo 'Hello ' . (isset($name) ? $name : 'John Doe') . '!';


阅读全文 »

字符串 函数 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

返回值

返回转换后的字符串。

注释

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

阅读全文 »

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

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

      示例1
<?php 
// 示例 1$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0];
 // piece1echo $pieces[1];
 // piece2// 示例 2$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user;
 // fooecho $pass;
 // *?>

      示例2
<?php 
/*  字符串内不包含分隔字符时,  会简单返回只有一个原始字符串元素的 array。*/
$input1 = "hello";
$input2 = "hello,there";
$input3 = ',';
var_dump( explode( ',', $input1 ) );
var_dump( explode( ',', $input2 ) );
var_dump( explode( ',', $input3 ) );
?>

      示例3
<?php 
$str = 'one|two|three|four';
// 正数的 limitprint_r(explode('|', $str, 2));
// 负数的 limitprint_r(explode('|', $str, -1));
?>

阅读全文 »

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

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

      示例1
<?php 
if (!($fp = fopen('date.txt', 'w'))) {
    return;
}
fprintf($fp, "%04d-%02d-%02d", $year, $month, $day);
// will write the formatted ISO date to date.txt?>

      示例2
<?php 
if (!($fp = fopen('currency.txt', 'w'))) {
    return;
}
$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
// echo $money will output "123.1";
$len = fprintf($fp, '%01.2f', $money);
// will write "123.10" to currency.txtecho "wrote $len bytes to currency.txt";
// use the return value of fprintf to determine how many bytes we wrote?>

阅读全文 »

错误处理 函数 预定义常量

发表日期:2021-07-01 10:18:48 | 来源: | 分类:错误处理 函数

预定义常量

下列常量作为 PHP 核心的一部分总是可用的。

注意:     你可以使用它们在中的常量名称; 但是在 PHP 之外,例如在之中, 你必须使用二进制位掩码来代替。  

错误和日志记录
常量说明备注
1E_ERROR      (int)致命的运行时错误。这类错误一般是不可恢复的情况,例如内存分配导致的问题。后果是导致脚本终止不再继续运行。 
2E_WARNING      (int)运行时警告 (非致命错误)。仅给出提示信息,但是脚本不会终止运行。 
4E_PARSE      (int)编译时语法解析错误。解析错误仅仅由分析器产生。 
8E_NOTICE      (int)运行时通知。表示脚本遇到可能会表现为错误的情况,但是在可以正常运行的脚本里面也可能会有类似的通知。 
16E_CORE_ERROR      (int)在 PHP 初始化启动过程中发生的致命错误。该错误类似      E_ERROR,但是是由 PHP 引擎核心产生的。 
32E_CORE_WARNING      (int)PHP 初始化启动过程中发生的警告 (非致命错误) 。类似 E_WARNING,但是是由 PHP 引擎核心产生的。 
64E_COMPILE_ERROR      (int)致命编译时错误。类似 E_ERROR,但是是由 Zend 脚本引擎产生的。 
128E_COMPILE_WARNING      (int)编译时警告 (非致命错误)。类似 E_WARNING,但是是由 Zend 脚本引擎产生的。 
256E_USER_ERROR      (int)用户产生的错误信息。类似      E_ERROR,但是是由用户自己在代码中使用 PHP 函数 trigger_error()来产生的。 
512E_USER_WARNING      (int)用户产生的警告信息。类似      E_WARNING,但是是由用户自己在代码中使用 PHP 函数 trigger_error()来产生的。 
1024E_USER_NOTICE      (int)用户产生的通知信息。类似      E_NOTICE,但是是由用户自己在代码中使用 PHP 函数 trigger_error()来产生的。 
2048E_STRICT      (int)启用 PHP 对代码的修改建议,以确保代码具有最佳的互操作性和向前兼容性。PHP 5.4.0 之前的版本中不包含 E_ALL
4096E_RECOVERABLE_ERROR      (int)可被捕捉的致命错误。 它表示发生了一个可能非常危险的错误,但是还没有导致PHP引擎处于不稳定的状态。 如果该错误没有被用户自定义句柄捕获 (参见      set_error_handler()),将成为一个 E_ERROR 从而脚本会终止运行。自 PHP 5.2.0 起
8192E_DEPRECATED      (int)运行时通知。启用后将会对在未来版本中可能无法正常工作的代码给出警告。自 PHP 5.3.0 起
16384E_USER_DEPRECATED      (int)用户产生的警告信息。 类似 E_DEPRECATED, 但是是由用户自己在代码中使用PHP函数 trigger_error()来产生的。自 PHP 5.3.0 起
32767E_ALL      (int)PHP 5.4.0 之前为 E_STRICT 除外的所有错误和警告信息。PHP 5.4.x 中为 32767,      PHP 5.3.x 中为 30719,      PHP 5.2.x 中为 6143,      更早之前的 PHP 版本中为 2047。

上面的值(数值或者符号)用于建立一个二进制位掩码,来制定要报告的错误信息。

可以使用 按位运算符 来组合这些值或者屏蔽某些类型的错误。请注意,在之中,只有'|', '~', '!', '^' 和 '&' 会正确解析。

阅读全文 »

杂项 函数 show_source 别名 highlight_file()

发表日期:2021-07-01 10:15:44 | 来源: | 分类:杂项 函数

show_source

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

show_source别名 highlight_file()

说明

此函数是该函数的别名: highlight_file().

阅读全文 »

杂项 函数 unpack Unpack data from binary string

发表日期:2021-07-01 10:15:44 | 来源: | 分类:杂项 函数

      示例1
<?php 
$binarydata = "\x04\x00\xa0\x00";
$array = unpack("cchars/nint", $binarydata);
print_r($array);
?>

      示例2
<?php 
$binarydata = "\x04\x00\xa0\x00";
$array = unpack("c2chars/nint", $binarydata);
print_r($array);
?>

      示例3
<?php 
$binarydata = "\x32\x42\x00\xa0";
$array = unpack("c2/n", $binarydata);
var_dump($array);
?>

阅读全文 »

杂项 函数 usleep 以指定的微秒数延迟执行

发表日期:2021-07-01 10:15:44 | 来源: | 分类:杂项 函数

      示例1
<?php 
// Current timeecho date('h:i:s') . "\n";
// wait for 2 secondsusleep(2000000);
// back!echo date('h:i:s') . "\n";
?>

阅读全文 »

杂项 函数 die 等同于 exit()

发表日期:2021-07-01 10:15:43 | 来源: | 分类:杂项 函数

die

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

die等同于 exit()

说明

语法结构等同于 exit()

阅读全文 »

杂项 函数 ignore_user_abort 设置客户端断开连接时是否中断脚本的执行

发表日期:2021-07-01 10:15:43 | 来源: | 分类:杂项 函数

      示例1
<?php 
// Ignore user aborts and allow the script// to run foreverignore_user_abort(true);
set_time_limit(0);
echo 'Testing connection handling in PHP';
// Run a pointless loop that sometime // hopefully will make us click away from // page or click the "Stop" button.while(1){
    // Did the connection fail?    if(connection_status() != CONNECTION_NORMAL)    {
        break;
    }
    // Sleep for 10 seconds    sleep(10);
}
// If this is reached, then the 'break' // was triggered from inside the while loop// So here we can log, or perform any other tasks// we need without actually being dependent on the // browser.?>

阅读全文 »

杂项 函数 sapi_windows_cp_get Get current codepage

发表日期:2021-07-01 10:15:43 | 来源: | 分类:杂项 函数

sapi_windows_cp_get

(PHP 7 >= 7.1.0, PHP 8)

sapi_windows_cp_getGet current codepage

说明

sapi_windows_cp_get(string $kind = ""): int

Gets the current codepage.

参数

kind

The kind of operating system codepage to get, either 'ansi' or 'oem'. Any other value refers to the current codepage of the process.

返回值

If kind is 'ansi', the current ANSI code page of the operating system is returned. If kind is 'oem', the current OEM code page of the operating system is returned. Otherwise, the current codepage of the process is returned.

参见

阅读全文 »

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