Search code examples
phpsplittokenizeinformation-retrieval

how to save change from split content of text


I've managed to cut the string a sentence into a word. but the new results can be viewed in the browser when the program runs. but these results can not change the condition of the strings in the original text file. I want the contents of the original text file identical to compile the results in the browser. Well how ya how to store the results of the pieces of the word to the text file? in this case stored in notepad with a .txt extension.

To cut the text I use the following php code:

$width = strlen($openfile)/28000;
$wrapped = wordwrap($openfile, $width,'<br>');

//echo $wrapped;
$stringedit=str_replace(" ", "<br>", $openfile);
echo $stringedit;

result from browser is like this

enter image description here


Solution

  • the solution for it problem is like this ,it is 100% work:

     <?php
       $array_filename = glob('simpantoken/*.txt');
       foreach ($array_filename as $fileteks)
       {
        $stringteks = file_get_contents($fileteks); 
        $konversi = strtolower($stringteks);
        $jenistandabaca = array(',', '!', '?', '.', ':',';', '-');
        $hapustandabaca = str_replace($jenistandabaca,'',$konversi);
        $hapustandabaca = trim(preg_replace('/[^0-9a-z]+/i','', $konversi)); 
        $hapustandabaca = preg_replace('/[^a-z\d]+/i', '', $konversi);
        $hapustandabaca = preg_replace('/[^\w]+/','',$konversi);
        $hapustandabaca = preg_replace('/\W+/','',$konversi);
        $replacespasi = str_replace(" ", PHP_EOL, $konversi);
        $konversistring = explode("/", $konversi); 
        $array = preg_split('/[\pZ\pC]+/u', $konversi);
        $ubahkarakter = str_replace(" ", '<br/>', $konversi);
        if(strpos($konversi,' ') >  0)
        {    
          echo "ada spasi";
        }
         else
        {
            echo "tidak ada spasi";
         }
           $handle = fopen($fileteks, 'w');
           fwrite($handle, $replacespasi);
           fclose($handle);
          }
        ?>