Jump to content

Recommended Posts

An Example: I have a string that contains a sentence. The user inputs what they think the sentence might be about and php returns whether they were correct or incorrect.

Is there a function that will do that. It is a bit like selecting something from a database using the mysql_query("select * from myTable where name like '%W%'");?

Link to comment
https://forums.phpfreaks.com/topic/54936-solved-php-string-help/
Share on other sites

Split the sentences into words, assign each to it's own variable, and use the ereg function.

 

<html>
<body>

<!-- Guess Input -->

<form action="sentence.php" method="post">
What's the sentence about? <input type="text" name="guess" />
<input type="submit" />
</form

</body>
</html>

<?php

/*Sentence.php*/

$str1 = "The";
$str2 = "dog";
$str3 = "name";
$str4 = "was";
$str5 = "Rover";
$str6 = "The dog's name was Rover.";

if (!ereg('($str1)+', $_POST["guess"])) && (!ereg('($str2)+', $_POST["guess"])) && (!ereg('($str3)+', $_POST["guess"])) && (!ereg('($str3)+', $_POST["guess"])) && (!ereg('($str5)+', $_POST["guess"]))
{
echo "You're completely off.";
}
else
{
echo "Good guess! The actual sentence was " . "'" . $str6 . "'";
}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.