当前位置:网站首页>PHP reference manual string (7.2000 words)

PHP reference manual string (7.2000 words)

2022-04-23 19:31:00 Your brother's way of programming (love sharing)

<?php
$str=addcslashes("A001 A002 A003","A");
echo($str);// In uppercase A Put a backslash in front of \, Case sensitive 

 Insert picture description here

<?php
$str = "Welcome to Shanghai!";
echo $str."<br>";
echo addcslashes($str,'A..Z')."<br>";// There's capital A To Z Add a backslash in front of all the English between \
echo addcslashes($str,'a..z')."<br>";
// There are lowercase a To z Add a backslash between all \
echo addcslashes($str,'a..g');// Lowercase a To g This range is all added with a backslash \

 Insert picture description here

<?php
$str=addslashes('Shanghai is the "biggest" city in China.');// Only the quotation marks within single quotation marks or double quotation marks are added with backslashes 
echo($str);

 Insert picture description here

<?php
$str = "Who s' Bill Gates?";

echo addslashes($str);// Only quotation marks within single quotation marks or double quotation marks have backslashes 
?>

 Insert picture description here

<?php
$str=bin2hex("Shanghai");
echo($str);//Shanghai Convert to hex 

 Insert picture description here

<?php
$str=bin2hex("Shanghai");// Convert to hex 
echo "<br />";
echo pack("H*",bin2hex("Shanghai"));// Restore the original data 

 Insert picture description here

<?php
$str = "Hello World!";
echo chop($str,"World!");// Remove $str In variables World

 Insert picture description here

<?php
$str = "Hello World!\n\n";
echo $str."666";
echo "<br />";
echo chop($str)."666";// Remove \n\n

 Insert picture description here

<?php
echo chr(61);// The decimal system stands for ascll code 
echo "<br />";
echo chr(061);echo "<br />";// Octal stands for ascii code 

echo chr(0x61);echo "<br />";// Hexadecimal stands for ascii code 

 Insert picture description here

<?php
$str = "Shanghai";// The string is divided into characters one by one S h a n g h a i, After split , Add... To the split position .
echo chunk_split($str,1,'.');

 Insert picture description here

<?php
$str = "Shanghai";// Split after every six characters , After split , Add... To the split position ... If chong Less than six , Just put ... Add last 
echo chunk_split($str,6,'...');

 Insert picture description here

<?php
$str = ",2&5L;&\@=V]R;&0A `";
echo convert_uudecode($str);// decode 

 Insert picture description here

<?php
$str = "Hello world!";
$encodeString = convert_uuencode($str);// Encoding is equivalent to encryption 
echo $encodeString . "<br>";

 Insert picture description here

<?php
$str = "PHP is pretty fun!!";
$strArray=count_chars($str,1);// Model a ,ASCII  The value is the key name ( character ), The number of occurrences is the key value ( The number of times characters appear ):
foreach ($strArray as $key => $value) {
    
echo " character  <b>'".chr($key)."'</b>  Found  $value  Time .<br>";
}// How many times does each character appear ,chr The function representative shows ascii code 

 Insert picture description here

<?php
$str = crc32("Shanghai");
printf("%u\n",$str);// You don't understand what I mean? 
?>

 Insert picture description here

<?php
$str = "Hello world. I love Shanghai!";
print_r(explode(" ",$str));//( Split a string into arrays , Divide the space into lines )

 Insert picture description here

<?php
$str = 'one,two,three,four';
print_r(explode(",",$str,0));
// Split a string into arrays . Split into only one array element 

 Insert picture description here

<?php
$str = 'one,two,three,four';
print_r(explode(",",$str,-1));
//-1:four Don't , Replace the previous string with , Division , Into array elements 

 Insert picture description here

<?php
$number = 9;
$str = "Beijing";
$file=fopen('test.txt','w');// Write mode , open test.txt file 
echo fprintf($file,"%u %s",$number,$str);// Put the numbers $u  character string $s Write to test.txt In the document 

 Insert picture description here

<?php
print_r(get_html_translation_table());// The most common code 

 Insert picture description here

<?php
echo hebrev("? ???? ?????");// In the opposite direction 

 Insert picture description here

<?php
echo hebrevc("? ???? ?????\n? ???? ?????");// hold \n convert to <br>

 Insert picture description here

<?php
echo hex2bin("48656c6c6f20576f726c6421");
// Convert hexadecimal values to ascii code 

 Insert picture description here

<?php
$str = "This is some <b>bold</b> text.";
echo htmlspecialchars($str);// Original output 
echo "<br />";
echo htmlspecialchars_decode($str);// Parse and output the special characters in the string 
?>

 Insert picture description here

<?php
$arr = array('Hello','World!','I','love','Shanghai!');
echo implode(" ",$arr);// The array becomes a string , Divide the space into lines 

 Insert picture description here

<?php
$arr = array('Hello','World!','I','love','Shanghai!');
echo join(" ",$arr);//implode Another name for 

 Insert picture description here

<?php
echo lcfirst("WWWello world");// Turns the first character in a string to lowercase 

 Insert picture description here

<?php
echo levenshtein("Hello World","ello World");
echo "<br />";
echo levenshtein("Hello World","ello World",10,20,40);// Can't 

 Insert picture description here
 Insert picture description here

<?php
$str = "Hello World!";
echo $str . "<br>";
echo ltrim($str,"Hello");// Remove from the left side of the string $str Inside Hello These strings ,ltrim($str) Words . Yes, remove the space on the left 

 Insert picture description here

<?php
$str = "Shanghai";
echo md5($str);// encryption , No change 

 Insert picture description here

<?php
$str = "Shanghai";
echo md5($str,TRUE);// original  16  Character binary format 

 Insert picture description here

<?php
$filename = "test.txt";
$md5file=md5_file($filename);
echo $md5file;// File encryption , Does not change with refresh 

 Insert picture description here

<?php
echo metaphone("hello");// pronunciation 

 Insert picture description here

<?php
echo "One line.\nAnother line.";
echo "<br/>";
echo nl2br("One line.\nAnother line.");// stay \n Insert line break before 

 Insert picture description here

<?php
echo number_format("5000000");
echo "<br />";
echo number_format("5000000",2);// Keep two decimal places 

 Insert picture description here

<?php
$num = 4999.9;
$formattedNum = number_format($num)."<br>";// rounding 
echo $formattedNum;
$formattedNum = number_format($num, 2);// Keep two decimal places , Don't go into rounding 
echo $formattedNum;
?>

 Insert picture description here

<?php
echo ord("S");// a key : Of the first character ascii Code value 
// return S Of ascii Code value 

 Insert picture description here

<?php
parse_str("name=cyg&zge=60");
echo $name.$zge;// This function takes = The one on the left becomes a variable , On the right is the value of the variable . Use... Between multiple variables & Connect 

 Insert picture description here

<?php
parse_str("name=cyg&zge=60",$my);
print_r($my);//$my It means to become an array . such as name=cyg&zge=60 When it becomes an array Array ( [name] => cyg [zge] => 60 ) 

 Insert picture description here

<?php
$num1 = 123456789;
$num2 = -123456789;
$char = 50; // ASCII  character  50  yes  2

//  notes : Format value  "%%"  Return the percent sign 
printf("%%b = %b <br>",$num1); //  Binary number 
printf("%%c = %c <br>",$char); // ASCII  character 
printf("%%d = %d <br>",$num1); //  Signed decimal numbers 
printf("%%d = %d <br>",$num2); //  Signed decimal numbers 
printf("%%e = %e <br>",$num1); //  Scientific enumeration ( A lowercase letter )
printf("%%E = %E <br>",$num1); //  Scientific enumeration ( Capitalization )
printf("%%u = %u <br>",$num1); //  Unsigned decimal numbers ( just )
printf("%%u = %u <br>",$num2); //  Unsigned decimal numbers ( negative )
printf("%%f = %f <br>",$num1); //  Floating point numbers ( Depending on local settings )
printf("%%F = %F <br>",$num1); //  Floating point numbers ( Regardless of local settings )
printf("%%g = %g <br>",$num1); //  Shorter than  %e  and  %f
printf("%%G = %G <br>",$num1); //  Shorter than  %E  and  %f
printf("%%o = %o <br>",$num1); //  Octal number 
printf("%%s = %s <br>",$num1); //  character string 
printf("%%x = %x <br>",$num1); //  Hexadecimal number ( A lowercase letter )
printf("%%X = %X <br>",$num1); //  Hexadecimal number ( Capitalization )
printf("%%+d = %+d <br>",$num1); //  Symbol specifiers ( just )
printf("%%+d = %+d <br>",$num2); //  Symbol specifiers ( negative )
?>

 Insert picture description here

<?php
$str = "I=0Alove=0AShanghai!";
echo quoted_printable_decode($str);// analysis ascii code .
// for instance ,=0A Represents a space 

 Insert picture description here

<?php
$str = "Hello world. (can you hear me?)";
echo quotemeta($str);// Metacharacters are preceded by backslashes ( Metacharacters are characters of regular expressions )

 Insert picture description here

<?php
$str = "Hello World!";
echo rtrim($str,"World!");// Get rid of $str Dexter World!

 Insert picture description here

<?php
$str = "Shanghai";
echo sha1($str);// Refresh several times without changing 

 Insert picture description here

<?php
$str = "Shanghai";
echo sha1($str,true);// original  20  Character binary format 

 Insert picture description here

<?php
$filename = "test.txt";
$sha=sha1_file($filename);// Encrypt the file 
echo $sha;

 Insert picture description here

<?php
echo similar_text("Hello World","Hello Shanghai");
// The similarity between two strings is 6, Including Spaces . from 1 Here we go 

 Insert picture description here

<?php
similar_text("Hello World","Hello Shanghai",$percent);
echo $percent. "%";// Similarity degree % percentage 
// The similarity between two strings is 6, Including Spaces . from 1 Here we go 

 Insert picture description here

<?php
$number = 2;
$str = "Shanghai";
$txt = sprintf("There are %u million cars in %s.",$number,$str);
echo $txt;//%u It's the number.  %s Is string 
?>

 Insert picture description here

<?php
$str = "age:30 weight:60kg";
sscanf($str,"age:%d weight:%dkg",$age,$weight);// Input 
//  Display type and value 
var_dump($age,$weight);

 Insert picture description here

<?php
echo str_ireplace("WORLD","Shanghai","Hello world!");
// Case insensitive , Put the... Of the third parameter WORLD Replace with Shanghai

 Insert picture description here

<?php
$arr = array("blue","red","green","yellow");
print_r(str_ireplace("RED","pink",$arr,$i));// stay $arr Function , hold red Replace with pink. Case insensitive . The number of replacements is 1 individual 
echo " Replacement number :$i";

 Insert picture description here

<?php
$str = "Hello World";
echo str_pad($str,30,'.');// A total of thirty characters , Not enough . fill 

 Insert picture description here

<?php
$str = "Hello World";
echo str_pad($str,30,'.',STR_PAD_LEFT);// A total of thirty characters , Not enough . fill ( On the left )

 Insert picture description here

<?php
$str = "Hello World";
echo str_pad($str,30,'.',STR_PAD_BOTH);// A total of thirty characters , Not enough . fill ( Both sides )

 Insert picture description here

<?php
echo str_repeat("Shanghai",5);// Fill Shanghai five times 

 Insert picture description here

<?php
echo str_replace("world","Shanghai","Hello world!");// Case sensitive . Put the... Of the third parameter world Switch to shanghai

 Insert picture description here

<?php
echo str_rot13("I love Shanghai");// code 
echo "<br>";
echo str_rot13("V ybir Funatunv");// decode 

 Insert picture description here

<?php
echo str_shuffle("I love Shanghai");// Randomly scramble strings . The refresh effect is different 

 Insert picture description here

<?php
print_r(str_split("Shanghai"));// Turn a string into an array . Every character is an element 

 Insert picture description here

<?php
print_r(str_split("Shanghai",3));// Turn a string into an array . It can be divided into three elements 

 Insert picture description here

<?php
echo str_word_count("I love Shanghai!");// The number of words is three 

 Insert picture description here

<?php
print_r(str_word_count("I love Shanghai!",1));// The number of words is three , Turn a string into an array 

 Insert picture description here

<?php
print_r(str_word_count("I love Shanghai!",2));// The number of words is three , Turn a string into an array , The key name is the position of the subscript 

 Insert picture description here

<?php
print_r(str_word_count("I love Shanghai & good morning!",1));
print_r(str_word_count("I love Shanghai & good morning!",1,"&"));
// This means to put & Treat as a word 
?>

 Insert picture description here

<?php
echo strcasecmp("shanghai","SHANGHAI");
// Output 0 For equality . Case insensitive 

 Insert picture description here

<?php
echo strcasecmp("Hello world!","HELLO"); // 
// Case insensitive .( When there are many first parameters ) In contrast . Positive numbers 
echo "<br />";
echo strcasecmp("Hello world!","HELLO WORLD! HELLO!"); // string1  Less than  string2
// Case insensitive . The space is also called .( When there are many second parameters )
/// In contrast , negative .

 Insert picture description here

<?php
echo strchr("Hello world!","world");
// See where the second parameter appears in the first parameter , And output all the following characters 

 Insert picture description here

<?php
echo strchr("Hello world!","world",true);// return world Where the first parameter appears 、. Returns only the first character 

 Insert picture description here

<?php
echo strcmp("Hello world!","Hello world!");// Is case sensitive as like as two peas? , Just go back 0

 Insert picture description here

<?php
echo strcmp("Hello world!","Hello world!"); //  Two strings are equal 0
echo strcmp("Hello world!","Hello"); // string1  Greater than  string2:7( Positive numbers )
echo strcmp("Hello world!","Hello world! Hello!"); // string1  Less than  string2:-7( negative )

 Insert picture description here

<?php
echo strcspn("Hello world!","w");
//w Position in parameter 1 . from 0 Start counting 

 Insert picture description here

<?php
echo strip_tags("Hello <b>world!</b>");// Get rid of html label 

 Insert picture description here

<?php
echo strip_tags("Hello <b>world!</b>","<b>");// Get rid of html label , But you can use <b>

 Insert picture description here

<?php
echo stripcslashes("Hello \World!");// Remove the backslash 

 Insert picture description here

<?php
echo stripslashes("Who\'s Bill Gates?");// Remove backslash \

 Insert picture description here

<?php
echo stripos("You love php, I love php too!","PHP");//PHP The position of the first occurrence in the first parameter , from 0 Start counting 

 Insert picture description here

版权声明
本文为[Your brother's way of programming (love sharing)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231929018583.html