This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Functions, Part I Forum

View Course » View Exercise

348 points
D241245eab9265604f4d4c10d3e013b5?s=140&d=retro
Submitted by
Eriberto Torres
almost 3 years ago

Why my strpos() function doesn't work?

Hi people,

I'm trying solve this exercise: PHP > Functions, part I, String Functions II.

The exercise say:

On line 6, use strpos() passing in your name as the haystack and a letter from your name as the needle.
On line 13, test if strpos() === false where the needle is not in the haystack. Print out an error message inside your if block.

Original code look also:

<html>
<p>
<?php
// Print out the position of a letter that is in
// your own name

?>
</p>
<p>
<?php
// Check for a false value of a letter that is not
// in your own name and print out an error message

?>
</p>

And my code look also:

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

I upload this solved exercise on a web server and runs perfectlly, but the parser of exercise say: Oops, try again. Your first strpos() call should output a number.
Ever, and ever.

Can you help solve this issue?

Thanks a lot,

Eriberto Torres


0 votes

Best answer

permalink

348 points
D241245eab9265604f4d4c10d3e013b5?s=140&d=retro
Submitted by
Eriberto Torres
almost 3 years ago