This function can be used to determine the characters in a string and the number of times they are used.
syntax: count_chars(string,mode);
string – the input string
mode
This parameter will determine the output of the count_chars() function.
Following are the possible values and implications of this parameter.
0 – The function returns an array with the ASCII value of every possible character as the key and the number of occurrances in the string as the value.
1 – The function returns anarray with the ASCII values as keys and the number of occurrances as values. In this case, the function creates an array element for characters that occur atleast once in the string.
2 - The function returns anarray with the ASCII values as keys and the number of occurrances as values. The array elements will correspond to characters that are not present in the string.
3 – The function will just display all the characters that are present in the input string.
4 – The function displays all the characters that are not present in the input string.
Example input:
$str = "Rooney";
echo $str;
echo "
";
print_r(count_chars($str,1));
echo "
";
echo count_chars($str,3);
echo "
";
echo count_chars($str,4);
Example output:
Rooney
Array ( [82] => 1 [101] => 1 [110] => 1 [111] => 2 [121] => 1 )
Renoy
******
Showing posts with label strings. Show all posts
Showing posts with label strings. Show all posts
Friday, April 17, 2009
Wednesday, October 1, 2008
The ord() function
The ord() function returns the ASCII value of the first character of the string.
Syntax: ord(string);
string – the input string
Example input:
echo ord("Hello");
Example output:
72
Syntax: ord(string);
string – the input string
Example input:
echo ord("Hello");
Example output:
72
Saturday, September 13, 2008
The chop() function
This has the same syntax and performs the same function rtrim() does.
Labels:
chop,
chop function,
chop(),
chop() function,
php,
rtrim,
string manipulation,
strings,
strings in php,
syntax
Concatenation
In PHP, strings could be easily concatenated using the dot (.) operator.
Example inputs
$name=”Rick”;
echo “My name is “.$name;
2.
echo “My name is “.”Rick”;
3.
$str1 = “My name is”;
$str2 = “Rick”;
$str3 = $str1.$str2;
Example outputs
1.
My name is Rick.
2.
My name is Rick
3.
My name is Rick
Example inputs
$name=”Rick”;
echo “My name is “.$name;
2.
echo “My name is “.”Rick”;
3.
$str1 = “My name is”;
$str2 = “Rick”;
$str3 = $str1.$str2;
Example outputs
1.
My name is Rick.
2.
My name is Rick
3.
My name is Rick
Labels:
concatenation,
dot operator,
join strings,
php,
string manipulation,
strings
Subscribe to:
Posts (Atom)