PHP String Extraction
When you deal with strings in the PHP programming language, manipulation of said strings is often required. This can include trimming the string or pulling specific characters or words out of it for use elsewhere in the program. A series of functions built into PHP helps with this process.
-
Splitting Up String
-
If you need to split up a string to access different parts of it, the "chunk_split()" function performs this function by splitting it up on a specified delimiter, such as a comma or semicolon.
Extracting String From String
-
Extracting a small string from within a large body of text is a common occurrence, especially in situations where you need to check and see if a specified phrase occurs in said body of text. The "stristr()" function operates by taking in a large body of text and the sample you wish to extract, and returning "true" if the sample is found within the body.
-
Returning Portion of String
-
If you know the exact location of a string you want to extract from a body of text, you can use the "substr()" function. This function takes a body of text, a start point and an endpoint, and extracts the substring from the body of text that is defined by the starting and ending points. One common use for this is in extracting the extensions from filenames.
Multiplying String
-
The "str_repeat()" function allows you to set the number of times you want a specified piece of text repeated. When called, this function will return the string repeated as many times as you specified. This type of data extraction is especially useful when working with arrays and loops.
-