PHP txt Find (Question)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Method
Forum Newbie
Posts: 11
Joined: Tue Aug 26, 2003 5:50 am

PHP txt Find (Question)

Post 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!
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

use the nl2br() function
Method
Forum Newbie
Posts: 11
Joined: Tue Aug 26, 2003 5:50 am

Post by Method »

thanks lil
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

np
Method
Forum Newbie
Posts: 11
Joined: Tue Aug 26, 2003 5:50 am

Post 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...
User avatar
Rook
Forum Newbie
Posts: 10
Joined: Thu Aug 21, 2003 10:40 am
Location: Euless, Tx.
Contact:

Post 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.
Method
Forum Newbie
Posts: 11
Joined: Tue Aug 26, 2003 5:50 am

Post by Method »

i got it working...

thanks for all the help
Post Reply