How do I make my first strpos() call output a number?


#1


Functions, Part 1 - String Functions II


How do I print out the position of a letter in my name?


<html>
    <p>
    <?php
    // Print out the position of a letter that is in
    // your own name
    strpos("jamie", "j"); // 0
    strpos("jamie", "a");  // 1
    strpos("jamie", "mie"); // 
    strpos("jamie", "z");
    ?>
    </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("jamie", "z") === false) {
        print "Sorry, no 'z' in 'jamie";
    }
    ?>
    </p>
</html>


#2

Hi try that

echo strpos("jamie", "j"); // 0

#3

That works! Thanks!

Maybe I overlooked this before but when do you use 'print' vs 'echo' to output data?


#4

YOu can find it here


#5

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