PHP Classes

File: custom_word_solver.php

Recommend this page to a friend!
  Classes of Arturs Sosins   Word Solver   custom_word_solver.php   Download  
File: custom_word_solver.php
Role: Example script
Content type: text/plain
Description: Example using custom dictionary
Class: Word Solver
Generate words or anagrams from specified rules
Author: By
Last change:
Date: 11 years ago
Size: 1,528 bytes
 

Contents

Class file image Download
<?php
/*************************************************************
 * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com
 * Feel free to distribute and modify code, but keep reference to its creator
 *
 * Word Solver class can generate words or anagrams using provided rules, for example,
 * possible letters, placement of specific letter, which letters should be used together,
 * or using any character from specified alphabet.
 * This class can be used to generate solutions to scrabble, crosswords, anagrams
 * and other word games.
 *
 * For more information, examples and online documentation visit:
 * http://webcodingeasy.com/PHP-classes/Generate-words-from-specified-rules
**************************************************************/
include("./word_solver.php");
//extending
class custom_word_solver extends word_solver
{
   
/****************************
    * CUSTOM DICTIONARY FUNCTIONS
    ****************************/
   
    //initialize dictionary
   
protected function dictionary_init(){
       
$str = file_get_contents("./custom_dictionary.txt");
       
$parts = explode("\r\n", $str);
        foreach(
$parts as $part)
        {
           
$this->dict[mb_strtolower($part)] = true;
        }
    }
   
   
//return false if word is incorrect
    //or true if word is correct
   
protected function dictionary_check($word){
       
$ret = false;
        if(
strlen($word) > 2)
        {
            if(isset(
$this->dict[$word]))
            {
               
$ret = true;
            }
        }
        return
$ret;
    }
 }
?>