PHP Classes

PHP Word Search in Array: Search a word in a 2 dimension array of characters

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 308 All time: 7,340 This week: 49Up
Version License PHP version Categories
word-search 1.0.0GNU General Publi...5HTML, PHP 5, Searching, Text processing
Description 

Author

This class can search a word in a 2 dimension array of characters.

It can take a string with different rows of characters separated by | and splits it to extract the list of characters in the 2 dimension grid.

The class can search for a given word that may appear in the grid horizontally, vertically or diagonally.

In the end it can also display the grid of characters in an HTML table.

Innovation Award
PHP Programming Innovation award nominee
March 2017
Number 5


Prize: One downloadable e-book of choice by O'Reilly
Crossword is a well known puzzle game that consists in finding words from a list that appear in a grid laid out either horizontally or vertically.

This class can search a word in a 2 dimension array of characters, thus helping to find words in a crossword puzzle automatically.

Manuel Lemos
Picture of Ravindu Taveesha
  Performance   Level  
Name: Ravindu Taveesha <contact>
Classes: 3 packages by
Country: Sri Lanka Sri Lanka
Age: 34
All time rank: 26784 in Sri Lanka Sri Lanka
Week rank: 178 Up1 in Sri Lanka Sri Lanka Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

include ('wordsearch.php');

$wordsearch = new WordSearch();
$wordsearch->string = "KEEDKFORFEEDS|GEEESQUIZFEED|EEEQAPRACTICE|FEEGEEJACTICE|GEEQAPRACTICE|FEEDAPRACTICE|KEEKKFORFEEDS";
$wordsearch->word = "FEED";

?>

<html>
<body>
    <table>
        <tr>
            <td>
            <h4>Matrix</h4>
                <?php echo $wordsearch->gridHtml(); ?>
</td>
            <td>
                <h4>Result</h4>
                <?php echo $wordsearch->run()->resultHtml(); ?>
</td>
        </tr>
    </table>
</body>
</html>



Details

word-search

Search a word in a 2d array of characters using PHP

A word can me matched in 8 directions, The 8 directions are horizontally left, horizontally right, vertically up and 4 diagonal directions.

below example, in this string word FEED can be found in diffrent places

"KEEDKFORFEEDS|GEEESQUIZFEED|EEEQAPRACTICE|FEEGEEJACTICE|GEEQAPRACTICE|FEEDAPRACTICE|KEEKKFORFEEDS"

This class is help to find all occurances of word by converting string into 2d array.

word-search


  Files folder image Files (5)  
File Role Description
Accessible without login Plain text file example1.php Example Example script
Accessible without login Plain text file index.html Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Plain text file wordsearch.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:308
This week:0
All time:7,340
This week:49Up