Spell your phone number
Phone Spell class can generate words that represent dialing for provided phone number. It also calculates word weight in numbers to order found variations starting from most promising ones.
This class uses Pspell extension as default dictionary, but it is possible to extend class for custom dictionary usage.
Contents
Download
Example codes
<?php //it could take some time set_time_limit(0); //measure time $time = microtime(); $time = explode(" ", $time); $start = $time[1] + $time[0]; //declaring class instance include("./phone_spell.php"); $ws = new phone_spell(); echo "<pre>"; //your phone number here $arr = $ws->get("8004659269"); print_r($arr); //end time $time = microtime(); $time = explode(" ", $time); $end = $time[1] + $time[0]; $total_time = round(($end - $start), 4); echo "<p>PHP execution: ".$total_time." seconds.</p>"; ?>
Examples in action
Example scripts provided with package in action:
Method list
- Create instance
- Set letters to numbers
- Set idiom
- Get errors
- Get array of possible number/word combinations
Create instance
| Method name | new phone_spell() |
| Description | Create class instance |
Set letters to numbers
| Method name | set_letters($num, $abc) |
| Description | Provide letters for specific number. By default class uses standard scheme as 2 representing a, b and c, 3 representing d, e and f, etc |
| Input parameters | int $num - number for which letters will be used array $abc - letters which may replace specified number |
Set idiom
| Method name | set_idiom($idiom) |
| Description | If you use multiple idioms for dictionary, like class default Pspell does, then you can provide which idiom to use by specifying idiom identifier. |
| Input parameters | string $idiom - idiom identifier for dictionary |
| Input Example | set_idiom("en") |
Get errors
| Method name | get_errors() |
| Description | Returns array with errors |
Get array of possible number/word combinations
| Method name | get($number) |
| Description | Returns array of possible number/word combinations from your specified phone number |
Extending class
If you want to use custom dicionary, then you'll have to extend this class and override two functions
Dictionary init
| Method name | dictionary_init() |
| Description | Initialize dictionary. Do anything you need to do before using dicionary |
Check word
| Method name | dictionary_check($word) |
| Description | Check if word is valid |
| Input parameters | string $word - word that needs to be checked |
| Returns | Return true if word is valid or false if invalid |
Latest changes
None for now
Awards
Phone Spell class was nominated to October Innovation Award, please support it by voting.
You may also be interested in:
Powered by BlogAlike.com










