Beruflich Dokumente
Kultur Dokumente
1.bin2hex()
Definition and Usage
The bin2hex() function converts a string of ASCII characters to hexadecimal
values. The string can be converted back using the pack() function.
Syntax
bin2hex(string)
Parameter Description
String Required. The string to be converted
Example
<html>
<body>
<?php
$str = "Hello world!";
echo bin2hex($str) . "<br>";
?>
</body>
</html>
Output
48656c6c6f20776f726c6421
Hello world!
2.chop()
Definition and Usage
The chop() function removes whitespaces or other predefined characters from
the right end of a string.
Syntax
chop(string,charlist)
Parameter Description
String Required. Specifies the string to check
3.Chunk_split()
Definition and Usage
The chunk_split() function splits a string into a series of smaller parts.
Note: This function does not alter the original string.
Syntax
chunk_split(string,length,end)
Parameter Description
String Required. Specifies the string to split
4.Explode
Definition and Usage
The explode() function breaks a string into an array.
Note: The "separator" parameter cannot be an empty string.
Note: This function is binary-safe.
Syntax
explode(separator,string,limit)
Parameter Description
separator Required. Specifies where to break the string
5.Implode
Definition and Usage
The implode() function returns a string from the elements of an array.
Syntax
implode(separator,array)
Parameter Description
Optional. Specifies what to put between the array elements.
separator
Default is "" (an empty string)
Example
<?php
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr)."<br>";
echo implode("+",$arr)."<br>";
echo implode("-",$arr)."<br>";
echo implode("X",$arr);*
?>
Output:
Hello World! Beautiful Day!
Hello+World!+Beautiful+Day!
Hello-World!-Beautiful-Day!
HelloXWorld!XBeautifulXDay!
6.join()
Definition and Usage
The join() function returns a string from the elements of an array.
The join() function is an alias of the implode() function.
Note: The join() function accept its parameters in either order. However, for
consistency with explode(), you should use the documented order of arguments.
Note: The separator parameter of join() is optional. However, it is
recommended to always use two parameters for backwards compatibility.
Syntax
join(separator,array)
Parameter Description
Optional. Specifies what to put between the array elements.
separator
Default is "" (an empty string)
7. lcfirst()
Definition and Usage
The lcfirst() function converts the first character of a string to lowercase.
Related functions:
ucfirst() - converts the first character of a string to uppercase
ucwords() - converts the first character of each word in a string to uppercase
strtoupper() - converts a string to uppercase
strtolower() - converts a string to lowercase
Syntax
lcfirst(string)
Parameter Description
Example:
<?php
echo lcfirst("Hello world!");
?>
Output:
hello world!
8. ltrim
Definition and Usage
The ltrim() function removes whitespace or other predefined characters from the
left side of a string.
Related functions:
rtrim() - Removes whitespace or other predefined characters from the right side
of a string
trim() - Removes whitespace or other predefined characters from both sides of a
string
Syntax
ltrim(string,charlist)
Parameter Description
String Required. Specifies the string to check
Example:
<?php
echo ord("h")."<br>";
echo ord("hello")."<br>";
?>
Output:
104
104
10.Parse_str()
Definition and Usage
The parse_str() function parses a query string into variables.
Syntax
parse_str(string,array)
Parameter Description
String Required. Specifies the string to parse
Example:
<?php
parse_str("name=Peter&age=43",$myArray);
print_r($myArray);
?>
Output:
Array ( [name] => Peter [age] => 43 )
11.Print
Definition and Usage
The print() function outputs one or more strings.
Note: The print() function is not actually a function, so you are not required to
use parentheses with it.
Tip: The print() function is slightly slower than echo().
Syntax
print(strings)
Parameter Description
Example
<?php
print "Hello world!";
?>
Output:
Hello world!
12.Printf:
Definition and Usage
The printf() function outputs a formatted string.
The arg1, arg2, ++ parameters will be inserted at percent (%) signs in the main
string. This function works "step-by-step". At the first % sign, arg1 is inserted,
at the second % sign, arg2 is inserted, etc.
Note: If there are more % signs than arguments, you must use placeholders. A
placeholder is inserted after the % sign, and consists of the argument- number
and "\$". See example two.
Tip: Related functions: sprintf(), vprintf(), vsprintf(), fprintf() and vfprintf()
Syntax
printf(format,arg1,arg2,arg++)
Parameter Description
Required. Specifies the string and how to format the variables
in it.
Possible format values:
%% - Returns a percent sign
%b - Binary number
%c - The character according to the ASCII value
%d - Signed decimal number (negative, zero or positive)
%e - Scientific notation using a lowercase (e.g. 1.2e+2)
%E - Scientific notation using a uppercase (e.g. 1.2E+2)
%u - Unsigned decimal number (equal to or greather than zero)
%f - Floating-point number (local settings aware)
%F - Floating-point number (not local settings aware)
Format %g - shorter of %e and %f
%G - shorter of %E and %f
%o - Octal number
%s - String
%x - Hexadecimal number (lowercase letters)
%X - Hexadecimal number (uppercase letters)
Additional format values. These are placed between the % and
the letter (example %.2f):
+ (Forces both + and - in front of numbers. By default, only
negative numbers are marked)
' (Specifies what to use as padding. Default is space. Must be
used together with the width specifier. Example: %'x20s (this
uses "x" as padding)
- (Left-justifies the variable value)
[0-9] (Specifies the minimum width held of to the variable
value)
.[0-9] (Specifies the number of decimal digits or maximum
string length)
Note: If multiple additional format values are used, they must
be in the same order as above.
13.rtrim()
"\0" - NULL
"\t" - tab
Charlist
"\n" - new line
"\x0B" - vertical tab
"\r" - carriage return
" " - ordinary white space
Example
Remove characters from the right side of a string:
<?php
$str = "Hello World!";
echo $str . "<br>";
echo rtrim($str,"World!");
?>
Output:
Hello World!
Hello
14..repeat()
Definition and Usage
The str_repeat() function repeats a string a specified number of times.
Syntax
str_repeat(string,repeat)
Parameter Description
String Required. Specifies the string to repeat
Required. Specifies the number of times the string will be
Repeat
repeated. Must be greater or equal to 0
Example:
<?php
echo str_repeat(".",13);
?>
Output:
………….
15.replace()
Definition and Usage
The str_replace() function replaces some characters with some other characters
in a string.
This function works by the following rules:
If the string to be searched is an array, it returns an array
If the string to be searched is an array, find and replace is
performed with every array element
If both find and replace are arrays, and replace has fewer elements
than find, an empty string will be used as replace
If find is an array and replace is a string, the replace string will be
used for every find value
Note: This function is case-sensitive. Use the str_ireplace() function to perform
a case-insensitive search.
Syntax
str_replace(find,replace,string,count)
Parameter Description
Find Required. Specifies the value to find
16.Split()
Definition and Usage
The str_split() function splits a string into an array.
Syntax
str_split(string,length)
Parameter Description
String Required. Specifies the string to split
Optional. Specifies the length of each array element. Default is
Length
1
Example
<?php
print_r(str_split("Hello",3));
?>
Output:
Array ( [0] => Hel [1] => lo )
17.Word_count()
Definition and Usage
The str_word_count() function counts the number of words in a string.
Syntax
str_word_count(string,return,char)
Parameter Description
String Required. Specifies the string to check
Example 2:
Return an array where the key is the position of the word in the string, and value
is the actual word:
<?php
print_r(str_word_count("Hello world!",2));
?>
Output:
Array ( [0] => Hello [6] => world )
18.Strcasecmp():
Definition and Usage
The strcasecmp() function compares two strings( case-insensitive).
Syntax
strcasecmp(string1,string2)
Parameter Description
string1 Required. Specifies the first string to compare
19.Strchr()
Definition and Usage
The strchr() function searches for the first occurrence of a string inside another
string.
This function is an alias of the strstr() function.
Note: This function is case-sensitive. For a case-insensitive search, use stristr()
function.
Syntax
strchr(string,search,before_search);
Parameter Description
String Required. Specifies the string to search
20.Strcmp()
Definition and Usage
The strcmp() function compares two strings.
Note: The strcmp() function is case-sensitive.
Syntax
strcmp(string1,string2)
Parameter Description
string1 Required. Specifies the first string to compare
Example:
<?php
echo strcmp("Hello","Hello");
echo "<br>";
echo strcmp("Hello","hELLo");
?>
Output:
0
-1
21. strcspn()
Definition and Usage
The strcspn() function returns the number of characters (including whitespaces)
found in a string before any part of the specified characters are found.
Syntax
strcspn(string,char,start,length)
Parameter Description
String Required. Specifies the string to search
22. count_chars()
Definition and Usage
The count_chars() function returns information about characters used in a
string.
Syntax
count_chars(string,mode)
Parameter Description
String Required. The string to be checked
For mode 3:
<?php
$str = "Hello World!";
echo count_chars($str,3);
?>
Output:
!HWdelor
For mode 1
<?php
$str = "Hello World!";
print_r(count_chars($str,1));
?>
Output:
Array ( [32] => 1 [33] => 1 [72] => 1 [87] => 1 [100] => 1 [101] => 1 [108] =>
3 [111] => 2 [114] => 1 )
23.md5()
Definition and Usage
The md5() function calculates the MD5 hash of a string.
The md5() function uses the RSA Data Security, Inc. MD5 Message-Digest
Algorithm.
The MD5 Message-Digest Algorithm: "The MD5 message-digest algorithm
takes as input a message of arbitrary length and produces as output a 128-bit
"fingerprint" or "message digest" of the input. The MD5 algorithm is intended
for digital signature applications, where a large file must be "compressed" in a
secure manner before being encrypted with a private (secret) key under a
public-key cryptosystem such as RSA."
Syntax
md5(string,raw)
Parameter Description
String Required. The string to be calculated
Optional. Specifies hex or binary output format:
Raw TRUE - Raw 16 character binary format
FALSE - Default. 32 character hex number
EXAMPLE
<?php
$str = "Hello";
echo "The string: ".$str."<br>";
echo "TRUE - Raw 16 character binary format: ".md5($str, TRUE)."<br>";
echo "FALSE - 32 character hex number: ".md5($str)."<br>";
?>
Output:
The string: Hello
TRUE - Raw 16 character binary format: ‹™SÄa–¨'«øÄx
FALSE - 32 character hex number: 8b1a9953c4611296a827abf8c47804d7