I am using the snoopy class to retrieve the text from a remote page. After I do this I use a function that I found on php.net called get_between() which allows me to store a string that exists inbetween 2 strings in a variable.

I need to store each line of text in an array. If I do the following then each line of text as the text appeared on the HTML page is output to the browser.

echo htmlspecialchars($text);

here is an example of what gets output to the browser by the above code.

205 Found - 06/12/2007 Southern California A.A. - TRA & CLOSED SUBARU
13 Found - 06/13/2007 Aloha AA - HAWAII Wednesday Sale

Is there a PHP function or does anyone have any code that will store each line in an array? Keep in mind that as the information is stored in the $text variable it is one continuous string and is not on separate lines.

Greg

    If the output looks exactly as above (line breaks are HTML line breaks), you can explode the string on <br> or <br /> or however it is written in the code.

      If, as Kudose said, the lines are output as you indicated with html line breaks, then this will create an array of all of the lines:

      $lines_array = explode("<br>", $text); OR $lines_array = explode("<br />", $text);

      If it doesn't, and each line starts with a # and the word "Found", then you could use preg_split with the PREG_SPLIT_DELIM_CAPTURE flag to create the array. Someone who is better at regular expressions than I am could easily tell you the correct regex to use.

        Each line is not separated by a <br> tag. If you look at the HTML source each item is on its own line, but not on the HTML page.

        I need to know how to use any number followed by the word found as my delimeter, but at the same time my delimeter needs to be at the beginning of each line after I put the variable into the array.

          padanaram wrote:

          If you look at the HTML source each item is on its own line

          Well, then there are line breaks - explode() on the newline characters (\n, \r, \r\n depending upon which O/S and application you might be dealing with).

            Write a Reply...