Jump to content


Checking for specific words in a array

  • Please log in to reply
2 replies to this topic

#1 Bricker

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 14 June 2006 - 06:44 PM

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
<!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">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>File Testing</title>

<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" />

Here is the php page:
    $dream = $_POST['dreamDetail'];
    $words = explode(';', $dream);    
    foreach ($words as $word)
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

#2 poirot

  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 14 June 2006 - 06:47 PM

str_word_count maybe?

[a href=\"http://www.php.net/str_word_count\" target=\"_blank\"]http://www.php.net/str_word_count[/a]
~ D Kuang

#3 Bricker

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 14 June 2006 - 07:45 PM

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

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

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

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?

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users