Error: first strpos() call should output a number


#1

I have been stuck on this code for a couple of days!!! The instructions are:

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.

This is my code:

strpos("tiffany", "ff");
strpos("tiffany","a");
?>



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

}

I keep getting an error that my first strips() should output a number. I am really lost!


#2

@ttw6168,
Try using

<php
   print strpos("tiffany","a");
?>

#3

thank you that worked!


#4

Hi everyone,

I got this error message too, but my strpos() is already outputing a number, so i'm quite lost :

$strpos = strpos("armand", "d");
echo $strpos;

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

if (strpos("armand", "e") === false)
{
print "

Sorry, no e in armand

";
}
// prints the "Sorry" message

Also, first time posting here, so let me know if i'm doing something wrong.

Thanks


#5

try
print strpos("string","s");


#6

Thanhs you, i've fixed and it worked :wink:)


#7



<?php
// Print out the position of a letter that is in
// your own name
strpos("sravani", "s");
strpos("sravani","a");

?>
</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("sravani","h") === false)
{
      print strpos("sravani","a");

}

can anyone help me
it results an error message like "Oops, try again. Your first strpos() call should output a number."


#8

@sravanisuresh
try using

echo strpos("sravani", "s");

And maybe to get idear about echo or print
http://stackoverflow.com/questions/1647322/whats-the-difference-between-echo-print-and-print-r-in-php


#9

thank you for the link


#10

Hey, for me it's not working any suggestion.
Here is my code:

<?php
// Print out the position of a letter that is in
// your own name
strpos("Chris","h"); //0
strpos("Chris","z"); //2
?>



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

What am I doing wrong?! :confused:


#11

// Print out the position of a letter that is in
// your own name
strpos("Chris","h"); 
strpos("Chris","z");
?>

you didn't print position of a letter that is in your own name.


#13

@ronn1e92 Hey Ron! You should write something like this:

print strpos("Chris","h");
So, just write print :wink:

The other part of code looks good :wink:


#14

Ok, I have tried all suggestions on here and nothing is working. What is wrong with this code?

<?php
// Print out the position of a letter that is in
// your own name
strpos("Muddy","h"); //0
strpos("Muddy","z"); //2
?>

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


#15

A post was split to a new topic: Unexpected o/p:


#17