Bifalgorithm post · Computer science one · Comparisons

How can you extract substrings from a string in PHP?

How can you extract substrings from a string in PHP? (Computer science one · Comparisons) — "43. Strings 1 $name = \"Thomas Alan Waits\"; 2 3 $firstName = subs…

Ideas in this flowchart

  • Strings und Teilzeichenketten
  • Die Variable $name enthält den vollständigen String "Thomas Alan Waits".
  • substr() extrahiert einen Teil eines Strings anhand von Startposition und optionaler Länge.
  • substr($name, 0, 6) ergibt "Thomas" und wird in $firstName gespeichert.
  • substr($name, 7, 4) ergibt "Alan" und wird in $middleName gespeichert.
  • substr($name, 12) ergibt "Waits" und wird in $lastName gespeichert.
  • Der optionale Längenparameter wird weggelassen.
  • Dadurch wird der gesamte verbleibende Rest des Strings zurückgegeben.
Feed/

How can you extract substrings from a string in PHP?

No cover

Channel

Computer science one

1 page

"43. Strings 1 $name = \"Thomas Alan Waits\"; 2 3 $firstName = substr($name, 0, 6); //\"Thomas\" 4 $middleName = substr($name, 7, 4); //\"Alan\" 5 $lastName = substr($name, 12); //\"Waits\" In 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.