Received me an order. As I described the TK:
- There is a file in which several articles
- Each line is divided by three or more Enter.
- The article consists of a heading, first line, and text,
- All other lines where paragraphs are less than three ...
etc.
Wrote a script in Notepad ++. For breakdown and definition of paragraphs used the symbol \n
.
Example (this code broke my text into array elements, divided by three paragraphs):
$arraytext= explode("\n\n\n", $contents);
When the customer began to check, it turned out that he did not manually break the file. And it copies the text from the editor - in each line there are incomprehensible spaces. I copied them and skipped through a script to display the character code:
$i=0; $lines = file('111.txt'); foreach($lines as $single_line){ echo ord($single_line[0]).'<br>'; }
As a result, I received this list of codes:
10 32 32 32 32 10 32 32 32 32 32 32 32 32 32 32 32 32 32 32
How I see the solution to the problem: replace all characters with codes 10 and 32 with \n
, then delete the extra \n
and my script will work with the content.
Problem : what is the code of the newline character \n
, and how to find and replace codes 10 and 32? As far as I understand, the str_replace
function str_replace
not work here.
If there are other solutions to my problem, I will be glad to know.