} $range = implode('', $range); $query = trim($query); $pattern = preg_replace('/[^a-z]/i', "[{$range}]", $query); $pattern = "/{$pattern}/i"; $words = file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'words.txt'); $result = array(); foreach ($words as $word) { if (strlen(trim($word)) != strlen($query)) { continue; } if (preg_match($pattern, $word)) { $result[] = trim($word); } } return $result; } if (isset($argv) && count($argv) >= 1) { if (count($argv) < 2) { echo "Usage: php wordfind.php format [exclude]\n"; echo "Example: php wordfind.php appl_ aiou\n"; exit; } $range = array(); if (isset($argv[2])) { $range = str_split($argv[2]); } $result = wordfind($argv[1], $range); echo implode("\n", $result); exit; }
<?php if (isset($_GET['q'])) { require 'wordfind.php'; $exclude = isset($_GET['lz']) ? str_split($_GET['lz']) : array(); $result = wordfind($_GET['q'], $exclude); header('Content-type: application/json'); echo json_encode($result); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> p { clear: both; } label { float: left; width: 100px; padding: 10px; } input { font-size: 18pt; letter-spacing: 5px; } #res { position: absolute; top: 0; right: 0; width: 40%; background-color: #ddd; overflow: scroll; height: 100%; } .hide { display: none; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> var qt = null; $(document).ready(function() { $('input').keyup(function(evt) { clearTimeout(qt); qt = setTimeout(function() { update(); }, 500);