Re: Php - String end of line
All lines (if breaking) contain \r, \n, or \r\n depending on the operating system. You can also try looking into using PHP's file() function. It parses a large string and breaks it into an array delimited by line returns.
Re: Php - String end of line
This is a special text it was scanned via scanner then processed via third party program so believe me there are some lines without \n or \r or any other combo as far as i know unless there is a way to see those hidden line breaks etc or a text editor or program that adds them to every line.
it looks like this btw in the original word document i have say a paragraph with 5 lines if i copy this paragraph to notepad i now have 4 lines or 3 so it rearranges according to the real amount of line brakes and i need to keep the original ratio...
Re: Php - String end of line
Can you attach that document?
If it doesn't have those hidden characters, then the document does not have any line returns in it at all. Those three ways are how a computer reads line returns.
1 Attachment(s)
Re: Php - String end of line
Ok here is a sample document.
Re: Php - String end of line
Well, there is only one line in that document. That is why it won't find more than one hidden line return character.
Also, remember that PHP parses plain text a whole lot better than a document with stylized text.
Re: Php - String end of line
Can you elaborate on your answer a bit
how can you tell there's only one line and how does parsing helps me here?
Re: Php - String end of line
Just because the document contains multiple lines, that is because it has line wrapping. However, the text itself is not in anyway multiline. Because this is the case, you cannot parse it by lines. You could split it by the number of words, or even by periods. But, the text itself is only one line.
Re: Php - String end of line
Ok i see that i need to write my own line wrapping function for this, just a few questions left.
1. Since that was just a sample document and there are some new line characters in the real document what is the easiest way to see them?
2. What should i add to the end of each line, i.e is there any real difference between \n and \r\n (will the printer actually print differently according to this)?
Re: Php - String end of line
Remember that when working with hidden characters you must use double-quotes and not single-quotes. That's the only way to find/replace/split them.
The difference between \n, \r, or \r\n is in the operating system which writes the text document. Windows uses \r\n, Mac uses \n, and I cannot remember, but some other base uses just \r, or at least it used to. I do not believe that just \r is common anymore.
Re: Php - String end of line
Using single quotes only works if the text in the quotes has \n but that's useless since the text itself has hidden \n, i.e i already divided the text by \n so i know there is at least some there
is there some kind of a print or other command to print hidden characters inside the text and not with the text?
or did i misunderstood what you said?
echo "mytext\n"; // hello
echo 'mytext\n'; // hello\n
echo 'mytext'; // mytext but it has \n
Re: Php - String end of line
There is no way to print the actual hidden characters, but you can replace the characters with your own custom characters.
If you want to remove extra line returns from text, you can also use PHP's trim() function. That will remove all whitespace from the beginning and end of the string.
Re: Php - String end of line
Ok thanks a lot for your help and time i guess this wraps it up... :)
p.s
\r - mac
\n - linux
\r\n - windows
Re: Php - String end of line
No. Mac, which has UNIX as it's core, is \n. I'm a Mac user.
I posted this previously in this thread.
Quote:
Windows uses \r\n, Mac uses \n, and I cannot remember, but some other base uses just \r, or at least it used to. I do not believe that just \r is common anymore.
Re: Php - String end of line
Well if you are a mac user maybe you are right but the last 20 sites i've seen on google said other wise of course maybe there are different OS on mac i don't know...