cvs: pear /Text_LanguageDetect/docs example_web.php

From: Date: Tue, 17 Jan 2006 19:00:54 +0000
Subject: cvs: pear /Text_LanguageDetect/docs example_web.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-37612@lists.php.net to get a copy of this message
taak Tue Jan 17 19:00:54 2006 UTC Modified files: /pear/Text_LanguageDetect/docs example_web.php Log: - style issues - uses correct utf8 char length - added example of unicode block range detection http://cvs.php.net/viewcvs.cgi/pear/Text_LanguageDetect/docs/example_web.php?r1=1.2&r2=1.3&diff_format=u Index: pear/Text_LanguageDetect/docs/example_web.php diff -u pear/Text_LanguageDetect/docs/example_web.php:1.2 pear/Text_LanguageDetect/docs/example_web.php:1.3 --- pear/Text_LanguageDetect/docs/example_web.php:1.2 Wed Jan 4 05:54:26 2006 +++ pear/Text_LanguageDetect/docs/example_web.php Tue Jan 17 19:00:54 2006 @@ -4,15 +4,18 @@ * example usage (web) * * @package Text_LanguageDetect - * @version CVS: $Id: example_web.php,v 1.2 2006/01/04 05:54:26 taak Exp $ + * @version CVS: $Id: example_web.php,v 1.3 2006/01/17 19:00:54 taak Exp $ */ // browsers will encode multi-byte characters wrong unless they think the page is utf8-encoded -header('Content-type: text/html; charset=utf-8',true); +header('Content-type: text/html; charset=utf-8', true); require_once 'Text/LanguageDetect.php'; $l = new Text_LanguageDetect; +if (isset($_REQUEST['q'])) { + $q = stripslashes($_REQUEST['q']); +} ?> <html> @@ -22,12 +25,12 @@ <body> <h2>Text_LanguageDetect</h2> <? -echo "<small>supported languages:\n"; +echo "<small>Supported languages:\n"; $langs = $l->getLanguages(); sort($langs); foreach ($langs as $lang) { - echo ucfirst($lang), ', '; - $i++; + echo ucfirst($lang), ', '; + $i++; } echo "<br />total $i</small><br /><br />"; @@ -35,26 +38,35 @@ ?> <form method="post"> Enter text to identify language (at least a couple of sentences):<br /> -<textarea name="q" wrap="virtual" cols="80" rows="8"><?= stripslashes($_REQUEST['q']) ?></textarea> +<textarea name="q" wrap="virtual" cols="80" rows="8"><?= $q ?></textarea> <br /> <input type="submit" value="Submit" /> </form> <? -if (isset($_REQUEST['q']) && $len = strlen($_REQUEST['q'])) { - if ($len < 50) { # this value was picked somewhat arbitrarily - echo "warning: string not very long ($len chars)<br />\n"; - } - - $result = $l->detectConfidence($_REQUEST['q']); - - if ($result == null) { - echo "Text_LanguageDetect cannot identify this piece of text.\n"; - } else { - echo "Text_LanguageDetect thinks this text is written in <b>{$result['language']}</b> ({$result['similarity']}, {$result['confidence']})\n"; - } +if (isset($q) && strlen($q)) { + $len = $l->utf8strlen($q); + if ($len < 20) { // this value picked somewhat arbitrarily + echo "Warning: string not very long ($len chars)<br />\n"; + } + + $result = $l->detectConfidence($q); + + if ($result == null) { + echo "Text_LanguageDetect cannot identify this piece of text. <br /><br />\n"; + } else { + echo "Text_LanguageDetect thinks this text is written in <b>{$result['language']}</b> ({$result['similarity']}, {$result['confidence']})<br /><br />\n"; + } + + $result = $l->detectUnicodeBlocks($q, false); + if (!empty($result)) { + arsort($result); + echo "Unicode blocks present: ", join(',', array_keys($result)), "\n<br /><br />"; + } } unset($l); +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + ?> </body></html>

« previous php.pear.cvs (#37612) next »