SoFunction
Updated on 2025-04-09

PHP character function collection page 1/2

AddSlashes: Add a slash of string.
bin2hex: The binary is converted to hexadecimal.
Chop: Remove continuous blanks.
Chr: Returns the character that is ordinal.
chunk_split: Divide the string into small segments.
convert_cyr_string: Convert the ancientslav string into other strings.
crypt: Encrypt the string with DES encoding.
echo: Output string.
exploit: Cut the string.
flush: Clear out the output buffer.
get_meta_tags: Extract all meta tagged information in the file.
htmlspecialchars: Convert special characters to HTML format.
htmlentities: Convert all characters into HTML strings.
implode: Turn the array into a string.
join: Turn the array into a string.
ltrim: Remove continuous blanks.
md5: MD5 of the calculation string.
nl2br: Convert line break characters to <br>.
Ord: Returns the ordinal value of the character.
parse_str:  Parse query Stand into variables.
print: Output string.
printf: Output formatted string.
quoted_printable_decode: Convert  qp encoded string into 8-bit string.
QuoteMeta: Add quotation symbols.
rawurldecode: Restore from URL-specific format string to normal string.
rawurlencode: Encode strings into URL-specific format.
setlocale: Configure regional information.
similar_text: Calculate string similarity.
soundex: Calculate the pronunciation value of the string
sprintf: Format the string.
strchr: Look for the first character to appear.
strcmp: String comparison.
strcspn: The length of different strings.
strip_tags: Remove HTML and PHP tags.
StripSlashes: Remove backslash characters.
strlen: Get the string length.
strrpos: Find the last occurrence of a character in the string.
strpos: Find the first occurrence of a character in the string.
strrchr: Get the string from the last occurrence of a certain character.
strrev: Reversal string.
strspn: Find out the number of masks of a string that falls on another string.
strstr: Returns the string from the beginning to the end of a string in the string.
strtok: Cut the string.
strtolower: All strings are converted to lowercase.
strtoupper: All strings are converted to uppercase.
str_replace: String replacement.
strtr: Convert certain characters.
substr: Take part of the string.
trim: Cut off the spaces at the beginning and end of the string.
ucfirst: Change the first character of the string to capitalize.
ucwords: Change the first letter of each character in the string to capitalize.


Return value: string
Function type: Data processing
Content description: This function allows the strings and quotation marks to be processed by the database to be added with slashes to allow the database query to operate smoothly. These characters that will be modified include single quotes ('), double quotes ("), backslash backslash (\) and null characters NUL (the null byte).
Reference: stripslashes() htmlspecialchars() quotemeta()


Return value: string
Function type: Data processing
Content description: This function converts binary strings into hexadecimal strings.
Usage example
Replenish:
josh@ (22-Jun-1999) wrote a function that converts hexadecimal into binary.
<?
function hex2bin($data) {
$len = strlen($data);
for($i=0;$i<$len;$i+=2) {
$newdata .= pack("C",hexdec(substr($string,$i,2)));
}
return $newdata;
}
?>


Return value: string
Function type: Data processing
Content description: This function clears continuous blanks of strings.
Usage example
<?
$trimmed = Chop($line);
?> 
Reference: trim()


Return value: string
Function type: Data processing
Content description: This function converts the ordinal number of characters into ASCII characters. This function is in contrast with ord().
Usage example
<?
$str .= chr(27);
$str = sprintf("The end character of the string is: %c", 27);
?> 
Reference: ord() sprintf()


Return value: string
Function type: Data processing
Content description: This function turns characters into small segments for other functions to use. For example, base64_encode. The parameter chunklen (76 characters) is inserted every 76 characters into end ("\r\n"). Returns the new string without changing the original string.
Usage example
Format the string $data into MIME BASE64
<?
$new_string = chunk_split(base64_encode($data));
?> 
Reference: ereg_replace()


Return value: string
Function type: Data processing
Content description: This function converts the Guslav string into other strings. The two parameters from  and to are characters, and their representative meanings are as follows:
k - koi8-r 
w - windows-1251 
i - iso8859-5 
a - x-cp866 
d - x-cp866 
m - x-mac-cyrillic


Syntax: string crypt(string str, string [salt]);
Return value: string
Function type: encoding processing
Content description: This function encrypts the string using UNIX’s standard encryption DES module. This is a one-way encryption function that cannot be decrypted. To compare strings, place the first two characters of the encrypted string in the salt parameter, and then compare the encrypted string.
For more detailed information, please refer to crypt in UNIX Manual (man).
In some newer UNIX versions, other encryption modules are provided in addition to DES, such as MD5. Some systems even use MD5 instead of DES. There are some changes in the salt parameter, depending on the length of the string passed to the salt parameter:
CRYPT_STD_DES - Standard DES encoding, enter 2 characters of salt.
CRYPT_EXT_DES - Extended DES encoding, enter 9 characters salt.
CRYPT_MD5 - MD5 encoding, enter 12 characters plus $1 salt.
CRYPT_BLOWFISH - Extended DES encoding, enter 16 characters plus $2$ salt.
In addition, if the salt parameter is not used, the program will be automatically generated.


Return value: None
Function type: PHP system function
Content description: This function outputs the string. Since it is not a real function, there is no return value either.
Usage example
<?php
echo "Hello World";
?> 
Reference: print() printf() flush()


Return value: array
Function type: Data processing
Content description: This function cuts the string according to the specified string or character separator. Returns the cut string to the array variable.
Usage example
<?
$pizza = "First, Second, Third, Fourth, Fifth, Sixth";
$pieces = explode(" ", $pizza);
?> 
Reference: implode()


Return value: None
Function type: Data processing
Content description: There is no input or output in this function. Send out the output buffer data and clear it out.


Syntax: array get_meta_tags(string filename, int [use_include_path]);
Return value: array
Function type: Data processing
Content description: This function takes out all the <meta ......> tagged data in homepage  and places array variables to return. For example
<html>
<head>
<meta content="Peng Wuxing">
<meta content="PHP BIBLE">
<title>PHP BIBLE</title>
</head><!-- This function processing only ends here ->
This function finds the meta tag, the string of the name attribute is the array index, and the content attribute string is the content information of the array. Note that this function is a PHP native function, and the Macintosh file format cannot be directly processed on the UNIX series platform because the line break characters are different. blake@ pointed out that (07-Jun-1999), the parameter filename can also be a URL, and the function will extract the file meta tag of the remote server. When processing the function, it ends when it encounters the </head> tag. If the <meta ....>  tag is placed on </head>, it will not be processed.


Syntax: string htmlspecialchars(string string);
Return value: string
Function type: Data processing
Content description: This function converts special characters into HTML string format ( &....; ). The most commonly used occasion may be to process the message version of customer messages.
& (and) Convert to &
" (double quotes) convert to "
< (less than) Convert to &lt;
> (greater than) Convert to &gt;
This function only converts the special characters above and will not all convert into the ASCII conversion specified in HTML.
Usage example
This is the example provided by aulbach@(27-Jan-1999)
<FORM ACTION=bla>
<H2>Restaurant Description<H2>
Name of restaurant:
<INPUT TYPE=text VALUE="<?
echo HTMLSpecialChars($restname); ?>"> 
<!-- Variable $restname is the sauce $restname="\"The White Horse\""; -->
<BR>
Enter a description (if you know HTML, you can use it directly): <BR>
<TEXTAREA ><?
echo HTMLSpecialChars($descript);
?></TEXTAREA>
<INPUT TYPE=submit>
</FORM> 
Reference: htmlentities() nl2br()


Syntax: string htmlentities(string string);
Return value: string
Function type: Data processing
Content description: This function is a bit like the htmlspecialchars() function, but this function will convert all string characters into HTML special word set strings. However, there will be many troubles when reading the web source code after conversion, especially the Chinese characters in the web source code will become unintelligible, and what you see on the browser is still normal.


Return value: string
Function type: Data processing
Content description: This function combines the contents of the array into a string, and the parameter glue is the separator symbol between the characters.
Usage example
<?
$colon_separated = implode(":", $array);
echo $colon_separated;
?> 
Reference: exploit() join() split()


Return value: string
Function type: Data processing
Content description: This function is an alias for the implode function.


Return value: string
Function type: Data processing
Content description: This function is used to delete continuous whitespace in strings.


Syntax: string md5(string str);
Return value: string
Function type: encoding processing
Content description: This function is used to calculate MD5. For MD5 encoding method, you can refer to RSA Data Security, Inc. MD5 Message-Digest Algorithm. RFC1321; or modern cryptography and its applications co-authored by Lai Xisong, Han Liang, Zhang Zhencheng, etc., 11.3.


Syntax: string nl2br(string string);
Return value: string
Function type: Data processing
Content description: This function converts line break characters into HTML line break instructions.
Reference: htmlspecialchars() htmlentities()


Return value: integer
Function type: Data processing
Content description: This function returns the ASCII (US National Standard Exchange Code) ordinal value of the character. This function is the opposite of chr() function.
Usage example
<?php
if (ord($str) == 10) {
echo("The first character of the string \$str  is a newline character.\n");
}
?> 
Reference: chr()


Syntax: void parse_str(string str);
Return value: None
Function type: Data processing
Content description: This function can parse the QUERY_STRING string of the GET method returned by the browser. The returned variable name and value are based on the name and value of QUERY_STRING.
Usage example
<?php
$str = "first=value&second[]=this+works&second[]=another";
parse_str($str);
echo $first; // Showing the "value" string
echo $second[0]; // Show the "this works" string
echo $second[1]; // Show "another" string
?> 


Return value: Boolean value
Function type: Data processing
Content description: This function outputs a string. If successful, return 1, and if failed, return 0. For example, if the browser of the customer suddenly hangs up during the transmission, the output will fail.
Reference: echo() printf() flush()


Return value: integer
Function type: Data processing
Content description: This function formats the string according to the content format specified by the parameter format. For details of the format, please refer to sprintf().
Reference: print() sprintf() flush()


Syntax: string quoted_printable_decode(string str);
Return value: string
Function type: encoding processing
Content description: This function can decode the quoted-printable string into an 8-bit encoded string. This function is similar to the imap_qprint() function. The only difference is that using the imap_qprint() function requires the system to add IMAP module, while this function does not require the IMAP module.


Return value: string
Function type: Data processing
Content description: This function adds a backslash "\" symbol before the string containing characters such as  . \\ + *? [ ^ ] ( $ ) .
Reference: addslashes() htmlentities() htmlspecialchars() nl2br() stripslashes()


Syntax: string rawurldecode(string str);
Return value: string
Function type: encoding processing
Content description: This function decodes the string. Decompose from the URL's string-specific format into a normal string. For detailed encoding and decoding information and specification documents, please refer to RFC 1738.
Reference: rawurlencode()


Syntax: string rawurldecode(string str);
Return value: string
Function type: encoding processing
Content description: This function encodes the string into a URL string-specific format, and special characters will be converted into a format with two sixteen-digit numbers added to the percentage symbol. For example, a space will become %20.
Usage example
<?php
echo '<a href="ftp://guest:', rawurlencode ('foo @+%/'), '@localhost/">';
?> 
Reference: rawurldecode()
12Next pageRead the full text