Bifalgorithm post · Computer science one · Arrays of Strings
How can you extract substrings from a string in PHP?
How can you extract substrings from a string in PHP? (Computer science one · Arrays of Strings) — "$name = \"Thomas Alan Waits\";\n\n$firstName = substr($name,…
Ideas in this flowchart
- Extracting name components with PHP substr()
- The source string is assigned to $name: "Thomas Alan Waits".
- The substr() function extracts portions of the source string.
- $firstName receives "Thomas" using position 0 and length 6.
- $middleName receives "Alan" using position 7 and length 4.
- $lastName receives "Waits" starting at position 12.
- Omitting the optional length parameter returns the entire remainder of the string.