PHP,分解一个文本文件,每个句子之间都有特殊字符
PHP, explode a text file that have special characters between every sentence
我有一个文本文件使用 Unicode 编码(有时它包含希伯来语),其中包含文本,每个句子之间有两个特殊字符 (■■),就像这样( alt + 2 + 5 + 4 ) 这是一个示例
"How are you, It's a cool day .. how can I read this sentence in a string variable with the quotes."■■
"This is second sentence I want it in another variable or in second cell in array."■■
This is third sentence. It is without quotes I want to read it to a string.■■
This is fourth sentence it includes an enter,
The fourth sentence isn't completed right yet.
The sentence doesn't completed until the special character is appears,
Maybe there a lot of lines in the same sentence.
This is the last part of the sentence■■
"This is the fifth sentence", this is the second part of the fifth sentence■■
Maybe between every two sentences there is a lot of empty lines, This is the sixth sentence■■
Thanks I wish anyone can help me with this, This is the last sentence■■
我纠正了这段代码,但它不起作用:
<?php
$file=file_get_contents("text_file.txt");
$file_= urldecode($file);
$sentences = explode('■■',$file_);
?>
当我为第一句话制作指定代码时(我没有把所有文件放在一起以便于阅读)我得到
Array ( [0] => ��"How are you, It s a cool day .. how can I read this sentence in a string variable with the quotes."�%�%
其他句子也一样..(我看到所有句子都在同一行)我的意思是没有输入
另一件事我想忽略两个句子之间的行我的意思是忽略 ■■
之后的空行
使用mb_split代替explode
另一种方法(因为它对我也不起作用):
<?php
$result = array();
$file = explode("■■", file_get_contents("sentences.txt")); /* EDIT : 2 x ALT254*/
foreach ( $file as $content ) {
$result[] = $content;
}
print_r($result);
?>
尝试使用:■或&#x25A0;而不是■。
我找到了解决方案...
我必须将文本文件保存为 UTF-8 而不是 Unicode。
现在可以了
谢谢
我有一个文本文件使用 Unicode 编码(有时它包含希伯来语),其中包含文本,每个句子之间有两个特殊字符 (■■),就像这样( alt + 2 + 5 + 4 ) 这是一个示例
"How are you, It's a cool day .. how can I read this sentence in a string variable with the quotes."■■
"This is second sentence I want it in another variable or in second cell in array."■■
This is third sentence. It is without quotes I want to read it to a string.■■
This is fourth sentence it includes an enter,
The fourth sentence isn't completed right yet.
The sentence doesn't completed until the special character is appears,
Maybe there a lot of lines in the same sentence.
This is the last part of the sentence■■
"This is the fifth sentence", this is the second part of the fifth sentence■■
Maybe between every two sentences there is a lot of empty lines, This is the sixth sentence■■
Thanks I wish anyone can help me with this, This is the last sentence■■
我纠正了这段代码,但它不起作用:
<?php
$file=file_get_contents("text_file.txt");
$file_= urldecode($file);
$sentences = explode('■■',$file_);
?>
当我为第一句话制作指定代码时(我没有把所有文件放在一起以便于阅读)我得到
Array ( [0] => ��"How are you, It s a cool day .. how can I read this sentence in a string variable with the quotes."�%�%
其他句子也一样..(我看到所有句子都在同一行)我的意思是没有输入
另一件事我想忽略两个句子之间的行我的意思是忽略 ■■
之后的空行使用mb_split代替explode
另一种方法(因为它对我也不起作用):
<?php
$result = array();
$file = explode("■■", file_get_contents("sentences.txt")); /* EDIT : 2 x ALT254*/
foreach ( $file as $content ) {
$result[] = $content;
}
print_r($result);
?>
尝试使用:■或&#x25A0;而不是■。
我找到了解决方案... 我必须将文本文件保存为 UTF-8 而不是 Unicode。 现在可以了 谢谢