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

Functions, Part I Forum

View Course » View Exercise

302 points
C5a6c47c86a202472c8f70481fb8b7e8?s=140&d=retro
Submitted by
Cara Ellis
over 3 years ago

what is wrong with my code??? please help!!!!

<?php

// Print out the position of a letter that is in
// your own name
$pos = strpos("Larry", "y");
print $pos;

?>

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

what is wrong with my code???PLEASE HELP!!!!!Oops, try again! Your first strpos() call should output a number.


21 votes

permalink

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

272 points
52cb169580ff33fc6700b1ac_818621470
Submitted by
SontoEremo
over 3 years ago

3 Comments

9209b9674f22ca0882b8188e06dca378?s=140&d=retro Natalie Rodriguez over 3 years ago

this works

52a5c9df548c355247001428_819369585 anonymous over 3 years ago

thx lots

54f47f79e39efe646d00727f_646434108 Hunter Steele over 2 years ago

totally wrx thnx


11 votes

permalink

Unfortunately, there are a lot of issues in that PHP course...

1012 points
Fbf4b4f9919affeb5791d42dc968d872?s=140&d=retro
Submitted by
azarich_ua
over 3 years ago


2 votes

permalink

try using variables for the input of strpos()

$name = "Brian";
$letter = "b"
$pos = strpos($name,$letter);
print $pos;

and for the second task change the letter variable and print it:

$letter = "s";
if($pos == false){
print "Sorry, no '{$letter}' in '{$name}'";
};

Hope that helps! - Niksda

704 points
5774397b4c432c220e0005b5_561341483
Submitted by
Niksda
over 3 years ago


0 votes

permalink

this code just work for me

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

// your own name
$pos = strpos("Larry", "y");
print $pos;
?>


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

</p>

302 points
C5a6c47c86a202472c8f70481fb8b7e8?s=140&d=retro
Submitted by
Cara Ellis
over 3 years ago


0 votes

permalink

This code worked for me.......

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


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

1061 points
523b8c2080ff333f75000222_135912984
Submitted by
Brian
over 3 years ago


0 votes

permalink

A lot of issues again and again...

1012 points
Fbf4b4f9919affeb5791d42dc968d872?s=140&d=retro
Submitted by
azarich_ua
over 3 years ago


0 votes

permalink

Is there a way to just skip this section because my code works but codecademy doesnt think it does.

141 points
A62fc1789cd9fd0dcf742e90cbfd3e1b?s=140&d=retro
Submitted by
MightyTrip
over 3 years ago

1 Comment

E1865fda28585205c1f729ef1ea11038?s=140&d=retro daireof over 3 years ago

put it between p tags " <?php code ?>"
if that doesn't work i'll send you solution


0 votes

permalink

in your if statement, it should be '==' not '==='

520 points
51e85864282ae36ec2000300_816931118
Submitted by
Minion
over 3 years ago

1 Comment

51dd8cea8c1ccc8a8a0098a9_824343249 Menixator over 3 years ago

both of them should work.


0 votes

permalink

I had problem passing this part even though my code was correct. What fixed it was removing the < p > around the message.

1036 points
60e00e98b25be27efe148f8bfdb86571?s=140&d=retro
Submitted by
braveface
over 3 years ago


0 votes

permalink

I've had no problems with this exercise. The code below works fine using variables...

<?php
// Print out the position of a letter that is in
// your own name
$haystack = "Mark Phoenix";
$needle = "k";
echo strpos($haystack, $needle);
?>
</p>
<p>
<?php
// Check for a false value of a letter that is not
// in your own name and print out an error message
$needle = "y";
if (!strpos($haystack, $needle)){
    echo "Sorry, no '$needle' in '$haystack'";
}
?>

796 points
50c257ea07d056aeb40080b9_372001912
Submitted by
Mark
almost 3 years ago


-1 votes

permalink

your code seems good.
check your code here, it's better than the Codecademy editor http://writecodeonline.com/php/
try putting each section of php between tags

630 points
E1865fda28585205c1f729ef1ea11038?s=140&d=retro
Submitted by
daireof
over 3 years ago

1 Comment

56ba16e3854138ca92000014_270405291 TashaJade almost 2 years ago

Link doesn't work