How can I recognise a <BR>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tramoman

    How can I recognise a <BR>

    Hi!
    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:


    <?php

    $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?
    Cheer
    Manuel
  • Sundial Services

    #2
    Re: How can I recognise a &lt;BR&gt;

    tramoman wrote:[color=blue]
    > 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.
    >
    > 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?[/color]

    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
    data.


    Comment

    • Michael Fesser

      #3
      Re: How can I recognise a &lt;BR&gt;

      .oO(tramoman)
      [color=blue]
      >$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...[/color]

      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).

      Micha

      Comment

      • Sundial Services

        #4
        Re: How can I recognise a &lt;BR&gt;

        Michael Fesser wrote:[color=blue]
        > 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).[/color]


        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.

        Comment

        Working...