Jump to content

Search for a word


Dizzee15

Recommended Posts

<?php

// First, read file into an array

$lines = file('information.txt');

$information = array();

foreach ($lines as $line)
{
    $words = explode('|', $line);
    foreach ($words as $word)
    {
        list($term, $count) = explode('=', $word);
        if (isset($information[$term]))
        {
            $information[$term] += $count;
        }
        else
        {
            $information[$term] = $count;
        } 
    }
}

// And now you can search the array for words.
$word_to_find = 'two';

if (isset($information[$word_to_find]))
{
    echo "$word_to_find is in the file and it's count is {$information[$word_to_find]}";
}

Link to comment
https://forums.phpfreaks.com/topic/164673-search-for-a-word/#findComment-868396
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.