Sonntag, 1. Juni 2014

PHP Basics: How can I print the n-th Character of a PHP String?

  1. // grabbing single elements out of a variable
  2.  
  3. // define the variable, in this case "NeilArmstrong"
  4. $variable_f = "NeilArmstrong";
  5.  
  6. // write the variable using the echo command and counting to a specific character, in this case number 0 and 5
  7. echo $variable_f[0];
  8. echo $variable_f[5];
Wrapping this into a php file and running it will give you the following output
"Nr" since the first Character of the string is "N" and the 5th is "r"

Keine Kommentare:

Kommentar veröffentlichen