I think there is a problem in exercise 3, nothing I do allows me to get through


#1

I have tried my own code, I have tried copying and pasting code from here on the forums. The results box shows it outputting a number, and printing an error message.

I even paid for Pro to get live help, but I can't find anywhere to click for live help.

Here is my code



<?php
// Print out the position of a letter that is in
// your own name
$name = strpos("Erik", "k");
print $name;
// print "
"
?>

<?php

if (strpos("Erik", "m") === false) {
    print "Sorry, no 'm' in 'Erik'";
}
?>
</p>

I have also tried using code from other posts int eh forum that says it works with the same results. Either the error that the first strpos call is supposed to output a number, it does but still fails me, or the second strpos call is supposed to output a helpful error, it does but still fails me.


#2

Here try this

<?php
// Print out the position of a letter that is in
// your own name
$name = strpos("Erik", "k");
print "$name <br><br>";

//the print statement you had here was causing the error
// the " " were not properly used
?>

<?php

if (strpos("Erik", "m") === false) {
    print "Sorry, no 'm' in 'Erik'";
}
?>
</p>

you can simplify the program by also doing this

<?php

if (!strpos("Erik", "m")) {
    print "Sorry, no 'm' in 'Erik'";
}
?>

or

<?php
// You can also use tenary operations
print !strpos("Erik", "m")? "Sorry, no 'm' in 'Erik'":" Found 'm' in 'Erik'";
?>

#3

With your code I get the error "Oops, try again. Your first strpos() call should output a number." Reset code, tried again and I get "Oops, try again. You should print out a useful error message for the failed strpos() call."


#4

You know what echo a message like this

echo "sorry not in there";

#5

Not sure what your asking. I tried an echo after the if function, before it, replaced the print with it. no change other than it showed the echo statement in the results window.

Still getting the same error.

Sorry for my delays in replying, I didn't think you would respond so quickly, left work and went home.


#6

Okay try this final one. its the evaluation system

<html>
    <p>

<?php
// Print out the position of a letter that is in
// your own name
$name = strpos("Erik", "k");
print "$name <br><br>";

//the print statement you had here was causing the error
// the " " were not properly used
?>
<?php
if (strpos("Erik","m") === false){
print "<p>Sorry, no m in Eric</p>";
}
?>
    </p>
</html>

#7

That worked. Thank you so much.

What is it about the

tag that changes it?

Again thanks for that, I've been struggling for awhile.


#8

I'm having the same problem as Erik, yet when I attempt the code that worked for him, I still get the same error message about the string not outputting a number.


#9

Did you found the solution ?
that worked for me.


<?php
// Affichez la position d'une lettre de votre prénom

$extrait = strpos("haby","b");

print $extrait;
?>
</p>
<p>
<?php
// Faite la vérification de la présence d'un caractère qui n'est pas
// dans votre nom et affichez un message d'alerte
 if(strpos("haby","i")===false){

     print "Désolé, il n'y a pas de 'i' dans 'haby'";

     }