Error on my PHP code?
-
this is a sample program which classifies a mail based on spam content. <?php function is_spam($text, $file, $split = ':', $regex = false){ $handle = fopen($file, 'rb'); $contents = fread($handle, filesize($file)); fclose($handle); $lines = explode("\n", $contents); $arr = array(); foreach($lines as $line){ list($word, $count) = explode($split, $line); if($regex) $arr[$word] = $count; else $arr[preg_quote($word)] = $count; } preg_match_all("~".implode('|', array_keys($arr))."~", $text, $matches); $temp = array(); foreach($matches[0] as $match){ if(!in_array($match, $temp)){ $temp[$match] = $temp[$match] + 1; if($temp[$match] >= $arr[$word]) return true; } } return false; } $file = 'spam.txt'; $str = 'This string has the word viagra and sex get viagra see viagra'; if(is_spam($str, $file)) echo 'this is spam'; else echo 'this is not spam'; ?> SPAM.TXT viagra:3 sex:3 porn:2 boobs:2 law firm:4 Error: Notice: Undefined index: viagra in C:\Documents and Settings\paramesh\Desktop\xampp\htdocs\n… on line 19 Notice: Undefined index: sex in C:\Documents and Settings\paramesh\Desktop\xampp\htdocs\n… on line 19 this is not spam
-
Answer:
seems you are confused between match, matches, matches[0] Check
Paramesh C at Yahoo! Answers Visit the source
Related Q & A:
- How can I debug my php code?Best solution by Stack Overflow
- What is error code 6 for Yahoo! mail?Best solution by in.answers.yahoo.com
- What does the error code 999 mean?Best solution by Yahoo! Answers
- What is server error code 40402?Best solution by Yahoo! Answers
- What is an easy code for a form in PHP?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.