<?php
/**
* Created by Phpstorm. * user:dy040
* DATE:2017/9/8
* time:16:46
*/
/*php also has an escape character/*/
echo "Hello php \" ";
$str = "Hello php \" ";
Echo $str;
echo "<br/>";
$a = addslashes ($STR); #包含转义字符一起输出
echo $a;
echo "<br/>";
$b = Stripcslashes ($STR); #去掉所有转义字符
Echo $b;
{
/* Get the length of the string in different encoding formats the kanji is three characters */
echo "<br/>";
echo strlen (' jhjkjhj me ');
}
{
/* Interception of strings */
echo "<br/>";
$str = ' that you world ';
Echo substr ($str, 0, 3); #返回结果是一个新字符串, the original string is unchanged
echo "<br/>";
Echo $str;
}
{
/* The interception of Chinese strings does not affect the original string */
echo "<br/>";
$str = ' Hello World ';
Echo mb_substr ($str, 0, 3);
echo "<br>";
Echo $str;
}
{
/* Three ways to compare strings can be used for account password verification */
echo "<br>";
echo strcmp (' 123 ', ' 124.0 ');//by Byte comparison,
Echo ' echo strnatcmp (' 123 ', ' 122.o '); #自然比较法 case-sensitive
Echo ' Echo strnatcmp (' A ', ' a ');
Echo ' Echo strnatcasecmp (' A ', ' a '); #自然比较法不区分大小写
Echo ' echo strncmp (' sad ', ' SDA ', 3); #比较字符串前几位大小区分大小写
/*STRNCASECMP () comparison string The first few bits are case-insensitive */
}
/* Retrieval of strings ===============================================================================*/
{
/*strstr () Determines whether a string contains a string */
echo "echo strstr (' asdfgh ', ' s ');//does not contain return-1 contains a return from the character truncated to the last one does not contain the string
}
{
/*substr_count () detects the number of occurrences of a string in a string */
echo "echo substr_count (' asdfghfgfg ', ' FG ');
}
/* Replace string ==================================================================*/
{
/*str_ireplace () */
echo "Echo str_ireplace (' 1 ', ' a ', ' 1234567891234 ');//Parameter 1: What the substitution parameter 2 replaced with what parameter 3 is replaced by the principal string
}
{
Substr_replace ()
echo "echo substr_replace (' 1234567891 ', ' a ', 5, 2);//start by capturing two characters from the fifth bit of the string to replace with a
}
/* Remove first space and clutter ==============================================================================*/
/*ltrim () Remove white space characters to the left of the string or specify a string */
echo "Echo LTrim (' DASD, ASD a ');
echo "Echo LTrim (' Asdffg, ', '); The second parameter has a fixed value of detail slightly
/*rtrim trim () */
{
The conversion between a string and an array
Echo ' $arr =[' name ' = ' XHQ ', ' age ' =>18, ' like ' and ' sport '];
$str = Implode ($arr, ' @ ');
Echo $str;
Print_r (Explode (' @ ', $str));
}
{
echo strrev (' qwe ');
}
?>
Methods for 8php strings