Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to etract string from a webpage and put it in a PHP variable
    primarykey
    data
    text
    <p>I found software called mecab that basically read a string and categorize the words into noun, verb, etc. What I'm trying to do is using a Google Search API to put the search function on my page so whenever I look up a location, e.g. Oxford street, a number of results will be displayed and mecab will take each of these result individually and do its job.</p> <p>What I'm stuck at is I don't know how to feed these results to mecab.</p> <p>Here are the codes:</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt; &lt;script type="text/javascript" src="http://www.google.com/jsapi?key=AIzaSyBX85AAhYSkh66lk8i2VBSqVJSY_462zGM"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function OnLoad() { // Create Search Control var searchControl = new google.search.SearchControl(); // Add searcher to Search Control searchControl.addSearcher( new google.search.WebSearch() ); searchControl.draw( document.getElementById( 'content' ) ); // Execute search searchControl.execute( '新宿' ); } // Load Google Search API google.load( 'search', '1' ); google.setOnLoadCallback( OnLoad ); &lt;/script&gt; &lt;div id="content"&gt;Loading...&lt;/div&gt; &lt;?php define('Mecab_Encoding', 'SJIS'); define('Mecab_ResultEncoding', 'UTF-8'); define('MeCab_Path', 'mecab.exe'); function morph_analysis($text) { $text = mb_convert_encoding($text, Mecab_Encoding, Mecab_ResultEncoding); $descriptorspec = array ( 0 =&gt; array ("pipe", "r"), // stdin 1 =&gt; array ("pipe", "w") // stdout ); $process = proc_open(MeCab_Path, $descriptorspec, $pipes); if (is_resource($process)) { // Feed string to macab fwrite($pipes[0], $text); fclose($pipes[0]); // Read the string while (!feof($pipes[1])) { $result .= fread($pipes[1], 4096); } fclose($pipes[1]); proc_close($process); $result = mb_convert_encoding($result, Mecab_ResultEncoding, Mecab_Encoding); $lines = explode("\r\n", $result); $res = array(); foreach($lines as $line) { if(in_array(trim($line), array('EOS', ''))) {continue;} $s = explode("\t", $line); $word = $s[0]; $words = explode(',', $s[1]); if ($words[0] == "名詞"){ $res[] = array( 'word' =&gt; $word, 'class' =&gt; $words[0], 'detail1' =&gt; $words[1], 'detail2' =&gt; $words[2], 'detail3' =&gt; $words[3], 'conjugation1' =&gt; $words[4], 'conjugation2' =&gt; $words[5] ); } } return $res; } else { return false; } } $text ="今日はいい天気です。"; $result = morph_analysis($text); echo "&lt;pre&gt;"; print_r($result); echo "&lt;/pre&gt;"; ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload