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

字符串 函数 quoted_printable_encode 将 8-bit 字符串转换成 quoted-printable 字符串

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

quoted_printable_encode

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

quoted_printable_encode将 8-bit 字符串转换成 quoted-printable 字符串

说明

quoted_printable_encode(string $str): string

返回 quoted-printable 格式的字符,该格式由 » RFC2045 6.7.章节里制定。

该函数与 imap_8bit() 函数十分相似,不同的是该函数不需要 IMAP 模块就能运行。

参数

str

输入的字符串。

返回值

返回编码之后的字符串。

参见

阅读全文 »

字符串 函数 rtrim 删除字符串末端的空白字符(或者其他字符)

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

      示例1
<?php 
$text = "\t\tThese are a few words :) ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump($text, $binary, $hello);
print "\n";
$trimmed = rtrim($text);
var_dump($trimmed);
$trimmed = rtrim($text, " \t.");
var_dump($trimmed);
$trimmed = rtrim($hello, "Hdle");
var_dump($trimmed);
// 删除 $binary 末端的 ASCII 码控制字符// (包括 0 - 31)$clean = rtrim($binary, "\x00..\x1F");
var_dump($clean);
?>

阅读全文 »

字符串 函数 setlocale 设置地区信息

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

      示例1
<?php 
/* Set locale to Dutch */
setlocale(LC_ALL, 'nl_NL');
/* Output: vrijdag 22 december 1978 */
echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978));
/* try different possible locale names for german as of PHP 4.3.0 */
$loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
echo "Preferred locale for german on this system is '$loc_de'";
?>

      示例2
<?php 
/* Set locale to Dutch */
setlocale(LC_ALL, 'nld_nld');
/* Output: vrijdag 22 december 1978 */
echo strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978));
/* try different possible locale names for german as of PHP 4.3.0 */
$loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
echo "Preferred locale for german on this system is '$loc_de'";
?>

阅读全文 »

字符串 函数 sha1_file 计算文件的 sha1 散列值

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

      示例1
<?php 
foreach(glob('/home/Kalle/myproject/*.php') as $ent){
    if(is_dir($ent))    {
        continue;
    }
    echo $ent . ' (SHA1: ' . sha1_file($ent) . ')', PHP_EOL;
}
?>

阅读全文 »

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

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

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

阅读全文 »

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

阅读全文 »

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

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

      示例1
<?php 
$hashed_password = crypt('mypassword');
 // 自动生成盐值/* 你应当使用 crypt() 得到的完整结果作为盐值进行密码校验,以此来避免使用不同散列算法导致的问题。(如上所述,基于标准 DES 算法的密码散列使用 2 字符盐值,但是基于 MD5 算法的散列使用 12 个字符盐值。)*/
if (hash_equals($hashed_password, crypt($user_input, $hashed_password))) {
   echo "Password verified!";
}
?>

      示例2
<?php 
// 设置密码$password = 'mypassword';
// 获取散列值,使用自动盐值$hash = crypt($password);
?>

      示例3
<?php 
if (CRYPT_STD_DES == 1) {
    echo 'Standard DES: ' . crypt('rasmuslerdorf', 'rl') . "\n";
}
if (CRYPT_EXT_DES == 1) {
    echo 'Extended DES: ' . crypt('rasmuslerdorf', '_J9..rasm') . "\n";
}
if (CRYPT_MD5 == 1) {
    echo 'MD5:          ' . crypt('rasmuslerdorf', '$1$rasmusle$') . "\n";
}
if (CRYPT_BLOWFISH == 1) {
    echo 'Blowfish:     ' . crypt('rasmuslerdorf', '$2a$07$usesomesillystringforsalt$') . "\n";
}
if (CRYPT_SHA256 == 1) {
    echo 'SHA-256:      ' . crypt('rasmuslerdorf', '$5$rounds=5000$usesomesillystringforsalt$') . "\n";
}
if (CRYPT_SHA512 == 1) {
    echo 'SHA-512:      ' . crypt('rasmuslerdorf', '$6$rounds=5000$usesomesillystringforsalt$') . "\n";
}
?>

阅读全文 »

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

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

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

阅读全文 »

字符串 函数 htmlentities 将字符转换为 HTML 转义字符

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

      示例1
<?php 
$str = "A 'quote' is <b>bold</b>";
// 输出: A 'quote' is &lt;
b&gt;
bold&lt;
/b&gt;
echo htmlentities($str);
// 输出: A &#039;
quote&#039;
 is &lt;
b&gt;
bold&lt;
/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>

      示例2
<?php 
$str = "\x8F!!!";
// 输出空 stringecho htmlentities($str, ENT_QUOTES, "UTF-8");
// 输出 "!!!"echo htmlentities($str, ENT_QUOTES | ENT_IGNORE, "UTF-8");
?>

阅读全文 »

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

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

      示例1
<?php 
$orig = "I'll \"walk\" the <b>dog</b> now";
$a = htmlentities($orig);
$b = html_entity_decode($a);
echo $a;
 // I'll &quot;
walk&quot;
 the &lt;
b&gt;
dog&lt;
/b&gt;
 nowecho $b;
 // I'll "walk" the <b>dog</b> now?>

阅读全文 »

字符串 函数 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),并且转换换行符

阅读全文 »

字符串 函数 htmlspecialchars 将特殊字符转换为 HTML 实体

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

      示例1
<?php 
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new;
 // &lt;
a href=&#039;
test&#039;
&gt;
Test&lt;
/a&gt;
?>

阅读全文 »

字符串 函数 join 别名 implode()

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

join

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

join别名 implode()

说明

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

阅读全文 »

字符串 函数 htmlspecialchars_decode 将特殊的 HTML 实体转换回普通字符

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

      示例1
<?php 
$str = "<p>this -&gt;
 &quot;
</p>\n";
echo htmlspecialchars_decode($str);
// 注意,这里的引号不会被转换echo htmlspecialchars_decode($str, ENT_NOQUOTES);
?>

阅读全文 »

字符串 函数 levenshtein 计算两个字符串之间的编辑距离

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

      示例1
<?php 
// 输入拼写错误的单词$input = 'carrrot';
// 要检查的单词数组$words  = array('apple','pineapple','banana','orange',                'radish','carrot','pea','bean','potato');
// 目前没有找到最短距离$shortest = -1;
// 遍历单词来找到最接近的foreach ($words as $word) {
    // 计算输入单词与当前单词的距离    $lev = levenshtein($input, $word);
    // 检查完全的匹配    if ($lev == 0) {
        // 最接近的单词是这个(完全匹配)        $closest = $word;
        $shortest = 0;
        // 退出循环;我们已经找到一个完全的匹配        break;
    }
    // 如果此次距离比上次找到的要短    // 或者还没找到接近的单词    if ($lev <= $shortest || $shortest < 0) {
        // 设置最接近的匹配以及它的最短距离        $closest  = $word;
        $shortest = $lev;
    }
}
echo "Input word: $input\n";
if ($shortest == 0) {
    echo "Exact match found: $closest\n";
}
 else {
    echo "Did you mean: $closest?\n";
}
?>

阅读全文 »

字符串 函数 lcfirst 使一个字符串的第一个字符小写

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

      示例1
<?php 
$foo = 'HelloWorld';
$foo = lcfirst($foo);
             // helloWorld$bar = 'HELLO WORLD!';
$bar = lcfirst($bar);
             // hELLO WORLD!$bar = lcfirst(strtoupper($bar));
 // hELLO WORLD!?>

阅读全文 »

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

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

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

阅读全文 »

字符串 函数 md5_file 计算指定文件的 MD5 散列值

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

      示例1
<?php 
$file = 'php-5.3.0alpha2-Win32-VC9-x64.zip';
echo 'MD5 file hash of ' . $file . ': ' . md5_file($file);
?>

阅读全文 »

字符串 函数 implode 将一个一维数组的值转化为字符串

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

      示例1
<?php 
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo $comma_separated;
 // lastname,email,phone// Empty string when using an empty array:var_dump(implode('hello', array()));
 // string(0) ""?>

阅读全文 »

字符串 函数 ltrim 删除字符串开头的空白字符(或其他字符)

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

      示例1
<?php 
$text = "\t\tThese are a few words :) ...  ";
$binary = "\x09Example string\x0A";
$hello  = "Hello World";
var_dump($text, $binary, $hello);
print "\n";
$trimmed = ltrim($text);
var_dump($trimmed);
$trimmed = ltrim($text, " \t.");
var_dump($trimmed);
$trimmed = ltrim($hello, "Hdle");
var_dump($trimmed);
// 删除 $binary 开头的 ASCII 控制字符// (从 0 到 31,包括 0 和 31)$clean = ltrim($binary, "\x00..\x1F");
var_dump($clean);
?>

阅读全文 »

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