Category:php
Article From:https://www.cnblogs.com/webdev8888/p/9127178.html
Remove the space trim ($processed string, $to remove the string) ltrim rtrim
<?php $ss="d i am a tesad"; $s=trim($ss,'d'); echo $s; ?>
Corresponding to python:a.lstrip (), a.rstrip (), a.strip (), a.strip ("ACC").


Inserts the character chunk_split into the string ($processed string, interval, inserted string)

<?php
echo chunk_split(“iamasmallgogo”,2,”,”);        ia,ma,sm,al,lg,og,o,
echo chunk_split(“iamasmallgogo”,1,”,”);        i,a,m,a,s,m,a,l,l,g,o,g,o,
?>

The frequency of each character in the numeric string is count_chars ($processed string, pattern).

<?php
$data=”i have some ii habasome”;
var_dump(count_chars($data,1));
var_dump(count_chars($data,3));
?>

array(10) {
[32]=>int(4)
[97]=>int(3)
[98]=>int(1)
[101]=>int(3)
[104]=>int(2)
[105]=>int(3)
[109]=>int(2)
[111]=>int(2)
[115]=>int(2)
[118]=>int(1)
}
string(10) ” abehimosv”

String the string into an array of delimitersarray explode ( string $delimiter , string $string [, int $limit ] )

<?php
$data=”i have some ii habasome”;
var_dump(explode(” “,$data));
var_dump(explode(” “,$data,2));
?>

array(5) {
[0]=>
string(1) “i”
[1]=>
string(4) “have”
[2]=>
string(4) “some”
[3]=>
string(2) “ii”
[4]=>
string(8) “habasome”
}
array(2) {
[0]=>
string(1) “i”
[1]=>
string(21) “have some ii habasome”
}

 Link the array into a string of separators

string implode ( string $glue , array $pieces )
string implode ( array $pieces )                Alias join

<?php

$array = array(‘lastname’, ’email’, ‘phone’);
$comma_separated = implode(“,”, $array);

echo $comma_separated; // lastname,email,phone

?>

string lcfirst ( string $str )Lowercase the first character of a string

string md5 ( string $str [, bool $raw_output = false ] )Calculating the MD5 hash value of a string

string nl2br ( string $string [, bool $is_xhtml = TRUE ] )Insert HTML line wrap before all new rows in the string.

string str_pad ( string $input , int $pad_length [, string $pad_string = ” ” [, int $pad_type = STR_PAD_RIGHT ]] ) Fill string to specified length

string str_repeat ( string $input , int $multiplier )   Repeating $input for $mutiplier times

str_replace  Substitution string

<?php
$s=”I’m Jack, I like CB, I’ve always been very nice.
$c=2;
echo str_replace(‘jack’,’tom’,$s).”\n”;
echo str_replace([‘Jack’,’cb’,’nice’],[‘tom’,’rb’,’bad’],$s).”\n”;
?>

I’m Jack, I like CB, I’ve always been very nice
I’m Tom, I like Rb, I’ve always been very bad
string str_shuffle ( string $str )

<?php

$str = “Hello Friend”;

$arr1 = str_split($str);
$arr2 = str_split($str, 3);

print_r($arr1);
print_r($arr2);

?>

Array
(
    [0] => H
    [1] => e
    [2] => l
    [3] => l
    [4] => o
    [5] =>
    [6] => F
    [7] => r
    [8] => i
    [9] => e
    [10] => n
    [11] => d
)

Array
(
    [0] => Hel
    [1] => lo
    [2] => Fri
    [3] => end
)
int stripos ( string $haystack , string $needle [, int $offset = 0 ] )

Return inCharacter stringhaystack inneedle The first digital position. It

int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )

Returnneedle stayhaystack The first appearance of the digital position. 

string strrev ( string $string )

Returnstring After the reversal of the string. It

 

;;;;;;;;;I don’t want to write it.

Link of this Article: PHP string processing

Leave a Reply

Your email address will not be published. Required fields are marked *