Jump to content

Checking for specific words in a array


Bricker

Recommended Posts

Hello,
My first post here. I have been searching the forums for my answer and have found things that are close but I can't quite put them together to help myself out...anyway here is my problem.

I am writing a simple dream interpretation program. It has a form with textarea to input your dream and then a submit button. This is sent to a php page for processing.

Here is what I have so far:
The Form Page
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>File Testing</title>
</head>

<body>
<form action="submit.php" method="post" name="dream">
<textarea name="dreamDetail" cols="40" rows="10"></textarea><br />
<input name="Submit" type="submit" value="Interpret Dream" />
</form>
</body>
</html>
[/code]

Here is the php page:
[code]
<?php
    $dream = $_POST['dreamDetail'];
    $words = explode(';', $dream);    
    foreach ($words as $word)
?>
[/code]
Of course this is very incomplete.

What I need to do is be able to search the associative array that is pulled in by _POST and do a word match with a file or a list of words with definitions attached to them.

An example of this can be seen on [a href=\"http://www.freakydreams.com\" target=\"_blank\"]www.freakydreams.com[/a]
Thank you
Link to comment
Share on other sites

Ok I've added this...
[code]
<?php
    $dream = $_POST['dreamDetail'];
    $words = explode(';', $dream);
    foreach ($words as $word);    
    print_r(str_word_count($word, 1));    
?>
[/code]

This puts each word in a seperate element in an array. Givs me this out put

[code]Array ( [0] => I [1] => dreamt [2] => that [3] => a [4] => fell [5] => off [6] => of [7] => a [8] => cliff [9] => last [10] => night )[/code]

Now what I need to do is identify words like cliff or fell and output them along with a definition of what they mean in a dream. I have access to a 350 word dictionary.

I guess its a matter of how to search through an array. How?
Link to comment
Share on other sites

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.