Page 1 of 1

fopen fgets....

Posted: Mon Feb 16, 2004 2:37 pm
by ol4pr0
Oke i got this working, however i need to add like single break tags in de output.

How would i do such a thing ( some example if possible. )

Code: Select all

// this is what i use to create the *.ans file

$infofile =  "addfaq.ans";
$openfile = fopen ($infofile, "w")
	or die("Couldnt open the file");
fwrite ($openfile, $faqadd);
fclose ($openfile);
$openfile  = fopen ($infofile, "r")
	or die("Couldnt open the file");
$file_size=filesize($infofile);
$file_contents= fread ($openfile, $file_size);
$msg="$file_contents"; // feedback
fclose ($openfile);

Code: Select all

// my code to open *.ans file 
// txt files gave me double breaks after every line 

$headline = "txt/headline.ans";
$openfile = fopen($headline , "r") 
	or die ("Sorry we couldnt process the request");
while (!feof ($openfile))
{
	$msg = fgets($openfile, 1024);
	echo "$msg", "\n";
}

Posted: Mon Feb 16, 2004 2:40 pm
by liljester
if you want line breaks in your html output, you need to use <br>.

Code: Select all

<?php

while(!feof($openfile)){
     $msg = fgets($openfile, 1024);
     print"$msg<br>\n";
}
?>

Posted: Mon Feb 16, 2004 2:48 pm
by ol4pr0
yea that will give me a <br> @ the end of the text feed.

However when i write the *.ans document. Lets say a large chunk of text, the output of that text wont have breaks in the lines like i added them in the input form.

Code: Select all

example :

menu:

something
something
something
the output of this would be

Code: Select all

menu:somethingsomethingsomething
And i also tried the

Code: Select all

<pre>$msg</pre>
however the output of this will be

Code: Select all

menu:

something

something

something
see what i mean?

Posted: Mon Feb 16, 2004 2:56 pm
by liljester
what kind of intput form? a textarea?

haha im so confused =/

Posted: Mon Feb 16, 2004 2:56 pm
by ol4pr0
liljester wrote:
print"$msg<br>\n";
}
?>

Code: Select all

/* i had this */
echo "$msg", "\n"; 

/* ", "\n"; 8*/
Dont know if you noticed that but.... looking at youre code again realized
that that might be the solution...


Thanks.

Posted: Mon Feb 16, 2004 2:58 pm
by liljester
=)

Posted: Mon Feb 16, 2004 2:58 pm
by ol4pr0
yes a textarea, do you know any other way ( maby little more fancy?)

Posted: Mon Feb 16, 2004 3:02 pm
by liljester
if you want to take the info from a text area and display it in a browser, nl2br() is a great function, it converts line feeds to html line breaks. haha if thats not what your after, could you post the code you're working with?

=)

Posted: Mon Feb 16, 2004 3:46 pm
by ol4pr0
The code i am working with is posted above all that is missing is the

Code: Select all

<form action=codeabove .php name=form>
let me look At the nl2br() guess i can find that on http://www.php.net

Posted: Mon Feb 16, 2004 3:53 pm
by ol4pr0
Ah ya .. the preg_replace thingie..

I think that is some weird <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>...