 |
|
คือเอามี code แรก คือ ป้อนไฟล์
Code (PHP)
<form action="index2.php" method="post" name="form1" id="form1">
Insert Text : <br />
<textarea name="text" rows="5" id="text" style="width:100%"></textarea><br />
<input type="submit" name="Submit" id="Submit" value="Submit" /> <input type="Reset" name="Reset" id="Reset" value="Reset" /><br /><hr />
</form>
ต่อไปคือ เราใช้โปรแกรมตัดคำอะครับ
Code (PHP)
<?php
if($_POST["text"]!= ""){
function swath($input_text){
$input_filename= "test.txt";
$output_filename= "output.txt";
$input_text = iconv('UTF-8', 'TIS-620', trim($input_text));
file_put_contents($input_filename, $input_text);
system( SWATH .'/swath.exe -b " " -d ' . SWATH . '/swath -m long < ' . $input_filename . ' > ' . $output_filename);
$raw = file_get_contents($output_filename);
$raw = iconv('TIS-620', 'UTF-8', rtrim($raw));
unlink($input_filename);
unlink($output_filename);
return $raw;
}//END FUNC SWATH
function multiexplode ($delimiters,$string) {
$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return $launch;
}
$trim = str_replace( " ", "", ($_POST["text"]) );
$w = swath ($trim);
$ex = multiexplode(array(" "),$w);
}
แล้วเราอยากให้มันแสดงผล
เช่น ลักษณะของผู้ที่มี ความสามารถด้านการ เรียนภาษาให้เก่ง เป็นผู้ที่มีความสามารถทางด้านการอ่าน
เป็น ลักษณะ ของ ผู้ ที่ มี ความ สามารถ ด้าน การ เรียน
ภาษา ให้ เก่ง เป็น ผู้ ที่ มี ความ สามารถ ทาง ด้าน การ อ่าน
ให้พอถึงประมาณหนึ่่ง มันจะตัดบรรทัดการตัดคำ
อีกอย่าง คืออยากเอา แต่ละคำที่ได้มาทำเป็น check box ให้ผู้ใช้เลือกว่าจะเอาคำไหนบ้าง
แล้วเรามีไฟล์ Code (PHP)
Code (PHP)
[php]<?php
if($_POST["q"]!=""){
//echo $_POST["q"];
echo $_POST["q"] ."<hr / >";
$q = trim( $_POST["q"] );
if( ord ( $q ) > "160" and ord ( $q ) < "250"){
$url = "http://th.asianwordnet.org/services/dictionary/xml/th2en/".urlencode($q);
}else{
$url = "http://th.asianwordnet.org/services/dictionary/xml/en2th/".$q;
}
$page = file_get_contents($url);
$xml = simplexml_load_string($page);
$str = "";
if($xml->rows > 0){
foreach($xml->data->item as $key => $item){
if($item->words != ""){
if( $item->ss_type == "n" ){
$str .= $item->words;
$str .= ", ";
if($item->translate){
$str .= $item->translate;
$str .= ", ";
}//END IF
}//END IF
else{
echo "ไม่ใช่คำนาม" ."<br />";
}
}//END IF
}//END foreach
}//END IF
function multiexplode ($delimiters,$string) {
$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return $launch;
}
$ex = multiexplode(array( " ", "," ),$str);
$stack = array( );
for($b=0; $b <= count($ex); $b++){
if( $ex[$b] != "" ){
array_push( $stack, $ex[$b]);
}
}
echo "<pre>";
print_r($stack);
echo "</pre><hr>";
foreach ($stack as $value) {
$link = "http://th.wikipedia.org/wiki/".$value;
echo "<a href=".$link.">". $value ."</a><br>";
}
}//END IF
?>
[/php]
ข้างบน ไฟล์ต้นฉบับ เป้นการ input ทีละคำอะ เราอยากเอาคำที่เราตัดมา ง่ายๆ เชื่อมจากไฟล์ก่อนหน้า ต้องทำไงอะครับ อยากให้มันรับค่าจาก check box ถามเยอะไปไหม =.=
Tag : PHP
|
|
 |
 |
 |
 |
Date :
2013-12-13 05:06:35 |
By :
conankungz |
View :
1129 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |