Methods for 8php strings

Source: Internet
Author: User

<?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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.