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

Functions, Part I Forum

View Course » View Exercise

170 points
4715f144df0f093d4009133067325617?s=140&d=retro
Submitted by
marshall_parr
over 2 years ago

Your first strpos() call should output a number.

I keep getting this error message with my code can someone spot what i have done wrong.

<?php
// Print out the position of a letter that is in
// your own name
strpos("marshall", "w"); //fault
?>


<?php
// Check for a false value of a letter that is not
// in your own name and print out an error message
if (strpos("marshall","w") === false) {
print "Sorry, no 'w' in 'marshall'";
}
?>


11 votes

permalink

It doesn't show in the directions, but you need to declare a variable and set it to your strpos() function - like this:

$charspot = strpos("Dave", "a");
echo $charspot;

1142 points
4c9dcf3e01b08de901809deef180f8fc?s=140&d=retro
Submitted by
systemAce31531
over 2 years ago

5 Comments

2c7f63be73fdafe7c76fae3588e8c86a?s=140&d=retro catronky over 2 years ago

This worked!

7598d9812ba33c79f03620ae3739e93f?s=140&d=retro sbang1203 about 2 years ago

Codeacademy should update the directions. As a beginner, I would've never known

Picture Nichole Shelton about 2 years ago

saved me loads of googling. Thanks!

16a1d5152f3a038716856f6dc437897d?s=140&d=retro yu21sei almost 2 years ago

Wow. What do you say when the answer that everybody else likes doesn't work? Hmmmmm..... Codecademy really writes frustrating courses!!!

56ba16e3854138ca92000014_270405291 TashaJade almost 2 years ago

Yayy!! This worked!! Thanking you!


2 votes

permalink

I must say i found this task one of the most confusing. Thank god for your aswer.

540 points
5c9cc60e34740d795909300f877a2d57?s=140&d=retro
Submitted by
murphy11
over 2 years ago


1 vote

permalink

<?php
$charspot = strpos("Evan", "a");
echo $charspot;
strpos("Evan", "e");
echo strpos("Evan", "e");
?>


<?php
if (strpos("Evan","h") === false) {
print "Sorry, no 'h' in 'Evan'";
}
?>

636 points
6f4e51b26ab9cfb8cdc35c8ca2ccbb9a?s=140&d=retro
Submitted by
wolflover12354
almost 2 years ago


0 votes

permalink

you should write like this :

// Print out the position of a letter that is in
// your own name

$myname = "marshall";
print strpos("marshall", "s"); // put any letter from the word "marshall" in order to print a number - that's the task

if(strpos($myname,"w") === false)
{
    print "Sorry, no 'w' in 'marshall' ";
}

581 points
Picture
Submitted by
Theo Arefb
over 2 years ago


0 votes

permalink

if i'm trying to use one of your codes and for me it says "Oops, try again. You should print out a useful error message for the failed strpos() call."

i'm confused, is [print "Sorry, no 'h' in 'Evan'";] not useful message? what message could be useful? somebody know what to do next?

179 points
2f3684832f186e736e2652d2ba6e9cfb?s=140&d=retro
Submitted by
Ivan
about 2 years ago


0 votes

permalink

if ((strpos("Evan","h") === false) {
print "Sorry, no 'h' in 'Evan'";
}

630 points
47a42e5f695548436bbba4afd2d512a0?s=140&d=retro
Submitted by
Joshua Paxton
about 2 years ago


-3 votes

permalink

This worked for me


<?php
// Print out the position of a letter that is in
// your own name
$charspot = strpos("Evan", "a");
echo $charspot;
strpos("Evan", "e");
echo strpos("Evan", "e");
?>


<?php
// Check for a false value of a letter that is not
// in your own name and print out an error message
if (strpos("Evan","h") === false) {
print "Sorry, no 'h' in 'Evan'";
}
?>

198 points
Aa77fee566042aeb379495e4c597dac4?s=140&d=retro
Submitted by
Evan Bridges
over 2 years ago

1 Comment

D8325ca3d25184888ff7e58b694dc491?s=140&d=retro Laurynas K almost 2 years ago

That was really confusing because in phpStrom IDE my own code worked just fine, try number of diffrent codes from this forums by deleting my own and pasting another users code and just your code worked, thank you!