Re: .DAT file with PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I didn't get the file, but

If the lines are seperated by <br>'s instead of newlines, then

$filename = "monkey.html";
$file_array = preg_split("/<br.*?>/", file_get_content($filename));
$rev_array = array_reverse($file_array);
$output = join("<br />", $rev_array);

This could be modded to maintain any arguments inside the <br> tag, by
replacing preg_replacing <br.*?> with $1\n, and then splitting on \n.


On 3/9/06, Paul Novitski <paul@xxxxxxxxxxxxxxxxxxx> wrote:
>
> At 07:05 PM 3/8/2006, Jabez wrote:
> >I used the following code that Paul suggested, but it didn't reverse my
> >content.
> >
> >The file I would want to have the content reversed is as attached.
> Chinese
> >characters is in the file so...
> >
> >Suggestions?
>
>
> Jabez,
>
> The data in your file is all in one text line.  You have inserted the
> string "<br>" between what I assume are your data elements, but not
> PHP linefeed characters.
>
> Try using "\n" (backslash-n) as your line delimiter and try again.
>
> By the way, I neglected to tell you earlier that when file() reads a
> file into an array, it includes the linefeed characters at the end of
> each array element.  These might or might not get in your way if
> you're outputting your data to an HTML file -- a linefeed will render
> as a whitespace character.  If you'll be writing the data to another
> text file where linefeeds are crucial, you may wish to massage the
> array to ensure that every array element (including the last one read
> from the original file) ends in \n.
>
> Regards,
> Paul
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux