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.
Feed/

How can you extract substrings from a string in PHP?

No cover

Channel

Computer science one

1 page

"$name = \"Thomas Alan Waits\";\n\n$firstName = substr($name, 0, 6); //\"Thomas\"\n\n$middleName = substr($name, 7, 4); //\"Alan\"\n\n$lastName = substr($name, 12); //\"Waits\"\n\nIn the final example, omitting the optional length parameter results in the entire remainder of the string being returned as the substring."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.