6 * @package Text_LanguageDetect
7 * @version CVS: $Id: example_web.php 205493 2006-01-18 00:26:57Z taak $
10 // browsers will encode multi-byte characters wrong unless they think the page is utf8-encoded
11 header('Content-type: text/html; charset=utf-8', true);
13 require_once 'Text/LanguageDetect.php';
15 $l = new Text_LanguageDetect;
16 if (isset($_REQUEST['q'])) {
17 $q = stripslashes($_REQUEST['q']);
23 <title>Text_LanguageDetect demonstration</title>
26 <h2>Text_LanguageDetect</h2>
28 echo "<small>Supported languages:\n";
29 $langs = $l->getLanguages();
31 foreach ($langs as $lang) {
32 echo ucfirst($lang), ', ';
36 echo "<br />total $i</small><br /><br />";
40 Enter text to identify language (at least a couple of sentences):<br />
41 <textarea name="q" wrap="virtual" cols="80" rows="8"><?= $q ?></textarea>
43 <input type="submit" value="Submit" />
46 if (isset($q) && strlen($q)) {
47 $len = $l->utf8strlen($q);
48 if ($len < 20) { // this value picked somewhat arbitrarily
49 echo "Warning: string not very long ($len chars)<br />\n";
52 $result = $l->detectConfidence($q);
54 if ($result == null) {
55 echo "Text_LanguageDetect cannot identify this piece of text. <br /><br />\n";
57 echo "Text_LanguageDetect thinks this text is written in <b>{$result['language']}</b> ({$result['similarity']}, {$result['confidence']})<br /><br />\n";
60 $result = $l->detectUnicodeBlocks($q, false);
61 if (!empty($result)) {
63 echo "Unicode blocks present: ", join(', ', array_keys($result)), "\n<br /><br />";
69 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */