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) stringcount_chars(string data, integer mode)
The count_chars function analyzes a string by the characters present. The modeargument 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 setwith the count for that character. If mode is 1, only the elements with count greater thanzero 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.
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 execute eval on a string that contained plain HTML? Probably because the code was stored in a database.
Be extremely careful when calling eval on any string that contains data that at any time came from form variables. This includes database fields that were originally set through a form. When possible, use nested $ operators instead of eval.<?
string sprintf(string format, ...)
The sprintf function operates identically to the printf function, except that instead of sending the assembled string to the browser, the string is returned. See the description of printf for a detailed discussion. This function offers an easy way to control the representation of numbers. Ordinarily PHP may print a double with no fraction
string str_repeat(string text, integer count)
The str_repeat function returns a string consisting of the text argument repeated the number of times specified by the count argument.
integer strcasecmp(string first, string second)
The strcasecmp function operates identically to strcmp with the exception that upper- and lowercase letters are treated as being identical. Check out soundex, metaphone, and similar_text for alternative ways of comparing strings.
This function is an alias to strstr.
integer strcmp(string first, string second)
The strcmp function compares the first string to the second string. A number less than
zero is returned if the first string is less than the second. Zero is returned if they are equal.
A number greater than zero is returned if the first string is greater than the second string. Comparisions are made by ASCII values. This function is safe for comparing binary data. Check out soundex, metaphone, and similar_text for alternative ways of comparing strings.
integer strcspn(string text, string set)
The strcspn function returns the position of the first character in the text argument that is part of the set argument. Compare this function to strspn.
string stristr(string text, string substring)
The stristr function is a case-insensitive version of strstr, below. A portion of the text argument is returned starting from the first occurrence of the substring argument to the end.
integer strlen(string text)
Use the strlen function to get the length of a string.
integer strpos(string data, string substring, integer offset)
The strpos function returns the position of the substring argument in the data argument. If the substring argument is not a string, it will be treated as an ASCII code. If the substring appears more than once, the position of the first occurrence is returned. If the substring doesn't exist at all, then FALSE is returned. The optional offset argument instructs PHP to begin searching after the specified position. Positions are counted starting with zero.
This function is a good alternative to ereg when you are searching for a simple string. It carries none of the overhead involved in parsing regular expressions. It is safe for use with binary strings.<?
This is an alias for strrpos.
integer strrpos(string text, string character)
The strrpos function operates similarly to strpos. It returns the last occurrence of the second argument in the first. However, only the first character of the second argument is used. This function offers a very neat way of chopping off the last part of a path, as in the example below.
integer strspn(string text, string set)
The strspn function returns the position in the first character in the text argument that is not part of the set of characters in the set argument. Compare this function to strcspan.
string strstr(string text, string substring)
The strstr function returns the portion of the text argument from the first occurrence of the substring argument to the end of the string. If substring is not a string, it is assumed to be an ASCII code.
An empty string is returned when substring is not found in text. You can use it as a faster alternative to ereg if you test for an empty string, as in the example below. The stristr function is a case-insensitive version of this function.<?
string strtok(string line, string separator)
The strtok function pulls tokens from a string. The line argument is split up into tokens separated by any of the characters in the separator string. The first call to strtok must contain two arguments. Subsequent calls are made with just the separator argument, unless you wish to begin tokenizing another string.
string substr(string text, integer start, integer length)
Use the substr function to extract a substring from the text argument. A string is returned that starts with the character identified by the start argument, counting from zero. If start is negative, counting will begin at the last character of the text argument instead of the first and work backward.
The number of characters returned is determined by the length argument or the beginning and end of the string. If length is negative, the returned string will end that many characters from the end of the string. In any case, if the combination of start and length calls for a string of negative length, a single character is returned.
This function is safe for use with binary strings.<?
PHP Related Interview Questions
|PHP Interview Questions||MySQL Interview Questions|
|PHP+MySQL Interview Questions||Drupal Interview Questions|
|MYSQL DBA Interview Questions||PHP5 Interview Questions|
|WordPress Interview Questions||Joomla Interview Questions|
|CakePHP Interview Questions||CodeIgniter Interview Questions|
|PHP7 Interview Questions|
An Introduction To Php
Variables, Operators, And Expressions
Classes And Objects
I/o And Disk Access
Time, Date, And Configuration Functions
Parsing And String Evaluation
Sorting Searching And Random Numbers
Integration With Html
Efficiency And Debugging
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.