如何保存文本拆分内容的更改
how to save change from split content of text
我已经设法将字符串 a sentence 切割成 word 了。但是程序运行时可以在浏览器中查看新的结果。但这些结果并不能改变原始文本文件中字符串的状态。我希望原始文本文件的内容与在浏览器中编译的结果相同。那么如何将单词的结果存储到文本文件中呢?在这种情况下,存储在扩展名为 .txt 的记事本中。
要剪切文本,我使用以下 php 代码:
$width = strlen($openfile)/28000;
$wrapped = wordwrap($openfile, $width,'<br>');
//echo $wrapped;
$stringedit=str_replace(" ", "<br>", $openfile);
echo $stringedit;
浏览器的结果是这样的
您可以使用:
file_put_contents ( $fileName, $stringedit); //here filename indicates the name/path of source file.
问题的解决方案是这样的,它是 100% 的工作:
<?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);
}
?>
我已经设法将字符串 a sentence 切割成 word 了。但是程序运行时可以在浏览器中查看新的结果。但这些结果并不能改变原始文本文件中字符串的状态。我希望原始文本文件的内容与在浏览器中编译的结果相同。那么如何将单词的结果存储到文本文件中呢?在这种情况下,存储在扩展名为 .txt 的记事本中。
要剪切文本,我使用以下 php 代码:
$width = strlen($openfile)/28000;
$wrapped = wordwrap($openfile, $width,'<br>');
//echo $wrapped;
$stringedit=str_replace(" ", "<br>", $openfile);
echo $stringedit;
浏览器的结果是这样的
您可以使用:
file_put_contents ( $fileName, $stringedit); //here filename indicates the name/path of source file.
问题的解决方案是这样的,它是 100% 的工作:
<?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);
}
?>