【发布时间】:2017-04-03 12:20:26
【问题描述】:
我有一个文本文件使用 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."�%�%
其他句子也一样..(我看到所有句子都在同一行)我的意思是没有输入
另一件事我想忽略两个句子之间的行我的意思是忽略■■之后的空行
【问题讨论】:
-
适用于所有 PHP 从 5.4 到 7.1
-
当我从问题中复制您的特殊字符时,我得到 Hex
A6而不是您建议的 HexFE,您确定您在explode()中使用了正确的分隔符吗??跨度> -
urldecode在里面做什么?它看起来不像是 URL 编码的数据。 -
当我第一次看到这个问题时,我很确定
url_decode()最初并不存在。请注释您可能做出的任何修改,因为更改问题使回答变得更加困难 -
很遗憾,我们只能猜测,除非您绝对确定您使用的分隔符是文件中的分隔符。知道这个字符是简单的单字节字符集还是多字节字符集也很有用?
标签: php string text-files special-characters explode