For the most part, the string functions create strings from other strings or report about the
properties of a string. The exception is the eval function, which executes a string as if it
were a line of code in your PHP script.
array count_chars(string data, integer mode) string
count_chars(string data, integer mode)
The count_chars function analyzes a string by the characters present. The mode
argument controls the return value. Modes 0, 1 and 2 return an array. Modes 3 and 4
return a string. If mode is left out, mode 0 is used.
If mode is 0, an array is returned indexed by ASCII codes, 0–255. Each element is set
with the count for that character. If mode is 1, only the elements with count greater than
zero are returned. If mode is 2, only the elements with count equal to zero are returned.
Mode 3 returns a string containing each character appearing in the input string. Mode 4
contains a string containing all characters not appearing in the input string.
<?
//print counts for characters found
foreach(count_chars("Core PHP", 1) as
$key=>$value)
{
print("$key:
$value
\n");
}
//print list of characters found
print("Characters: '". count_chars("Core
PHP", 3). "'
\n");
?>
eval(string phpcode)
The eval function attempts to execute the phpcode argument as if it were a line in
your PHP script. As with all strings, double quotes will cause the string to be evaluated
for embedded strings and other special characters, so you may wish to use single quotes
or escape dollar signs with backslashes.
In some ways, eval is like include or require. Beyond the obvious difference that
eval works on strings instead of files, eval starts in a mode where it expects PHP
code. If you need to switch to a mode where plain HTML is passed directly to the
browser, you will need to insert a closing PHP tag (?>). Why would you ever want to