Page 1 of 1

PHP txt Find (Question)

Posted: Fri Aug 29, 2003 2:57 pm
by Method
I am creating a site in which it will include("test.txt"); in an area of the body of the document...

I was wondering, is there a way to search that txt document and tell it to replace all the hard returns in the document to <br> so that it shows up that exact way in the final product? This way the person updating that information doesn't have to use tags...

Thanks all!

Posted: Fri Aug 29, 2003 2:58 pm
by liljester
use the nl2br() function

Posted: Fri Aug 29, 2003 3:00 pm
by Method
thanks lil

Posted: Fri Aug 29, 2003 3:00 pm
by liljester
np

Posted: Fri Aug 29, 2003 3:35 pm
by Method
it is still not doing what i wanted... i have the following code:

Code: Select all

<?
// Set the directory where the TXT files are located
$txtdir="txt/";
$news="test.txt";
$news=nl2br($news);
?>
and then in the body i call

Code: Select all

<?
include($txtdir.$news);
?>
but in the .txt file where i have returns, it will not show the returns on the webpage... that is what i am wanting to do...

Posted: Fri Aug 29, 2003 3:41 pm
by Rook
The function works on strings.. not entire files.

You need to do something like this:

Code: Select all

<?php
// Set the directory where the TXT files are located 
$arr = file($txtdir.$news);
foreach ($arr as $k => $v) {
	echo nl2br($v);
}

?>
- Rook.

Posted: Fri Aug 29, 2003 3:56 pm
by Method
i got it working...

thanks for all the help