Core PHP

String Editing Functions

String Editing Functions
chop()
This function is the same as rtrim().
chunk_split()
string chunk_split(string $sOriginal, int $iChunkSize = 76, string $sEndOfChunk = "\r\n")
This function returns the $sOriginal string with the $sEndOfChunk string inserted after every $iChunkSize characters.
Argument Description
string $sOriginal This is the original string that is to be split into chunks.
int $iChunkSize This is chunk size.
string $sEndOfChunk This is the string that delimits the ends of the chunks.
lcfirst()
string lcfirst(string $sOriginal)
This function returns the string $sOriginal with its first character changed to lowercase, if it is an uppercase letter.
Argument Description
string $sOriginal This is a string that will be made lowercase.
ltrim()
string ltrim(string $sOriginal, string $sStripped = ' \t\n\r\0\x0B')
This function returns the $sOriginal string with all of the characters in the string $sStripped trimed off the beginning of the string..
Argument Description
string $sOriginal This is a string that will be converted.
string $sStripped This is a string that holds the characters that will be stripped from the beginning of the string.
rtrim()
string rtrim(string $sOriginal, string $sStripped = ' \t\n\r\0\x0B')
This function returns the $sOriginal string with all of the characters in the string $sStripped trimed off the end of the string..
Argument Description
string $sOriginal This is a string that will be converted.
string $sStripped This is a string that holds the characters that will be stripped from the end of the string.
str_ireplace()
various str_replace(various $qSearch, various $qReplace, various $qTarget, int &$irCount = 0)
This function returns a copy of the string or array of strings $qTarget with each instance of $qSearch replaced by an instance of $qReplace. This is similar to str_replace(), except that the matching of $qSearch is done without respect to whether the characters are upper or lower case. If $qSearch and $qReplace are arrays, then the corresponding entries are matched with empty strings used for any missing replacements.
Argument Description
various $qSearch This is the string of the array of strings for which we are searching.
various $qReplace This is the string or the array of strings with which we are replacing $qSearch.
various $qTarget This is the string or the array of strings in which we are replacing $qSearch with $qReplace.
int &$irCount This is a reference that returns a count of the replaced strings.
str_pad()
string str_pad(string $sOriginal, int $iPadLength, string $sPadString = " ", int $iPadType = STR_PAD_RIGHT)
This function returns a padded copy of the string $sOriginal that is padded to the length $iPadLength with the string $sPadString, and is padded on the sides specified by $iPadType.
Argument Description
string $sOriginal This is the string that is to be padded.
string $sPadString This is the string that will be used to pad the string.
int $iPadType This specifies on which side the string will be padded.
  • STR_PAD_RIGHT
  • STR_PAD_LEFT
  • STR_PAD_BOTH
str_replace()
various str_replace(various $qSearch, various $qReplace, various $qTarget, int &$irCount = 0)
This function returns a copy of the string or array of strings $qTarget with each instance of $qSearch replaced by an instance of $qReplace. If $qSearch and $qReplace are arrays, then the corresponding entries are matched with empty strings used for any missing replacements.
Argument Description
various $qSearch This is the string of the array of strings for which we are searching.
various $qReplace This is the string or the array of strings with which we are replacing $qSearch.
various $qTarget This is the string or the array of strings in which we are replacing $qSearch with $qReplace.
int &$irCount This is a reference that returns a count of the replaced strings.
strtolower()
string strtolower(string $sOriginal)
This function returns the string $sOriginal with all of its alphabetic characters changed to lowercase, according to the current locale.
Argument Description
string $sOriginal This is a string that will be converted.
strtoupper()
string strtolower(string $sOriginal)
This function returns the string $sOriginal with all of its alphabetic characters changed to uppercase, according to the current locale.
Argument Description
string $sOriginal This is a string that will be converted.
strtr()
string strtr(string $sOriginal, string $sTarget, string $sReplacement)
string strtr(string $sOriginal, array $saReplacementPairs)
This function returns the string $sOriginal with all instances of each single character in $sTarget replaced by the corresponding character of $sReplacement. If $sTarget and $sReplacement are not the same length, all of the extra characters in the longer string will be ignored.
Argument Description
string $sOriginal This is a string that will be converted.
string $sTarget This is a string of characters that will be searched for inside $sOriginal.
string $sReplacement This is a string of characters that will be used to reaplace $sTarget.
substr_replace()
string substr_replace(string $sOriginal, string $sReplacement, integer $iStart, integer $iLength)
array substr_replace(array $saOriginal, array $saReplacement, array $iaStart, array $iaLength)
This function returns the string $sOriginal with the substring beginning at the index $iStart with the length $iLength replaced by the string $sReplacement. Alternatively, all of these arguments can be repalced by arrays.
Argument Description
string $sOriginal This is a string that will have its substring replaced
string $sReplacement This is the replacement string.
integer $iStart This markes beginning of the substring that will be replaced. If it is negative, it marks the distance from the end of the string.
integer $iLength This specifies the maximum length of the substring. If the length specifies beyond the end of the string, the extra length is ignored.
substr()
string substr(string $sOriginal, int $iStart, int $iLength = infinite)
This function returns a substring of characters from $sOriginal starting at $iStart and containing at most $iLength characters. If $iStart is greater than the number of characters in $sOriginal, FALSE is returned.
Argument Description
string $sOriginal This is a string that we will take the substring from.
int $iStart This marks where the substring begins. If this is negative, it takes the value from the end of the string.
int $iLength This is the maximum length of the substring.
trim()
string trim(string $sOriginal, string $sSet = " \t\n\r\0\x0B")
This function returns a string of characters which consists of $sOriginal with the whitespace characters in $sSet removed from the beginning and end of it. The default characters that are stripped are as followws:
  • " " = space
  • "\t" = horizontal tab
  • "\n" = linefeed
  • "\r" = carriage return
  • "\0" = null
  • "\x0B" = vertical tab
Argument Description
string $sOriginal This is a string that will be stripped of its initial and final whitespace characters.
string $sSet This string is the set of characters that will be removed.
ucfirst()
string ucfirst(string $sOriginal)
This function returns the string $sOriginal with its first character changed to uppercase, if it is a lowercase letter.
Argument Description
string $sOriginal This is a string that will be capitalized.
ucwords()
string ucwords(string $sOriginal, string $sDelimiters = " \t\r\n\f\v")
This function returns the string $sOriginal with the first character of each word changed to uppercase, if it is a lowercase letter. The set of delimiter characters specifies which characters are the first in each word. By default, the delimiters are s follows: space, tab, line feed, carriage return, form feed, and vertical tab.
Argument Description
string $sOriginal This is a string that will be capitalized.
string $sDelimiters This is a string contains the word dividing characters.
wordwrap()
string wordwrap(string $sOriginal, int $iLineLength = 75, string $sEndLine = "\n", bool $bCutAtLength = false)
This function returns the string $sOriginal with the string $sEndLine inserted every the $iLineLength characters or earlier to cut the string into $iLineLength sections. If $bCutAtLength is true, then a word that is longer than $iLineLength will be split at $iLineLength. Otherwise, words longe than $iLineLength will not be split.
Argument Description
string $sOriginal This is a string that will be word wrapped.
int $iLineLength This is the length before which the line should be wrapped.
string $sEndLine This string is inserted at the end of each line.
bool $bCutAtLength This designated whether or not we wrap in the middle of words that are longer than $iLineLength or just wrap at the end. This can create lines longer than $iLineLength, if it is false.
 
 

© 2007–2024 XoaX.net LLC. All rights reserved.