How can I recognise a

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I would like to make an algorith that recognise a Forced line break in
HTML or a normal text. For instance, I would like to store in one
array different lines of a string.

Here my attempt:


$line = "Pemberton Valley, Ayr

Available: Now

This property forms a three bedroom detached villa. It is offered on
an unfurnished basis. Please note that this property is not available
until the middle of December.

$explode = split('  ', $line);


I would like the first line of my string in the first element of the
array, the second line in the second element and so on...

If I put <BR> instead ' ' doesn t work.
Please, can you help me?

Re: How can I recognise a

tramoman wrote:
Quoted text here. Click to load it

Most likely, the text will be found to be separated by newline (\n), return
(\r), or some combination of the two.  This is probably what you want to
"split" on.  Once you have done that, you can trim the extraneous blanks...
you should also remove any newline or return bytes that may be found in the
data... and your line-breaks will be denoted by empty-string elements in
the resulting array.  Those you replace with <BR> tags.

I use the "strtr" function frequently, to replace the "\r\n" sequences often
found in input-data, with the "\n"s usually found in outputs of the same

Re: How can I recognise a


Quoted text here. Click to load it

You could try to split when multiple line breaks occur:

$explode = preg_split("#\r?\n(\r?\n)+#", $line);

Should work with Linux and Windows texts (different operating systems
use different line breaks).


Re: How can I recognise a

Michael Fesser wrote:
Quoted text here. Click to load it

It might be simplest to use 'strtr' to transform each of the various
possibilities (\n, \r, \r\n, \n\r) into just one, then work from there.

Site Timeline