String Functions I


#1

Error: Oops, try again. Did you remember to print your substring?

Code:

<html>
  <p>
    <?php
    // Get a partial string from within your own name
    // and print it to the screen!
    $planet = "Mars";
    
    $partial = substr($planet, 0, 1);
    print $partial;
    ?>
  </p>
  <p>
    <?php
    $planet = "Mars";
    // Make your name upper case and print it to the screen:
    $uppercase = strtoupper($planet)
    print $uppercase;
    ?>
  </p>
  <p>
    <?php
    $planet = "Mars";
    // Make your name lower case and print it to the screen:
    $lowercase = strtolower($planet)
    print $lowercase;
    ?>
  </p>
</html>

#2

Also have this error on next section:

Error: Oops, try again. Your first strpos() call should output a number. (Some say its a bug O.o)

Code:

<html>
    <p>
    <?php
    // Print out the position of a letter that is in
    // your own name
    $planet = strpos("Mars", "q");
    print $planet
    ?>
    </p>
    <p>
    <?php
    // Check for a false value of a letter that is not
    // in your own name and print out an error message
    if (strpos("Mars", "q") === false) {
        print "Sorry, could not find";
    }
    ?>
    </p>
</html>

#3

// Print out the position of a letter that is in
// your own name
$planet = strpos("Mars", "q");

In your case you try to find index of symbol q in string "Mars", but the string doesn't contain symbol q. Try to find symbol a: strpos (look to return section).


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.