0

hi, im having a bit of trouble learning php. My script is working but it is showing the amount of characters i am echoing out....heres the code.

$tireorder = 'you have ordered: '.$tireqty.' tires.' ;

//open the file and check to see if it exists//
$fp = fopen("file.txt","r+");
if(!$fp) {
echo "Your order could not be prossesed at this time";
exit;
}
//writing to a file//
fwrite($fp, $tireorder);

//closing the file//
fclose($fp);

//reading the file//
$data = @readfile("file.txt");


//echoing out//
echo $data;

?>

It writes to the text file - you have ordered: {tire amount} tires. {character amount}
Is there anyway to get rid of the character count?

all suggestions will help thanx :D

2
Contributors
10
Replies
11
Views
9 Years
Discussion Span
Last Post by iamthwee
0

I dunno, maybe you just need to write to a file:

<?php
$fp = fopen("file.txt","w") or die ("couldn't open!");
fwrite($fp, "blah\n");
fclose($fp);
?>
0

Thanks but it didnt work .... in your example it would write out - blah 4 ...... it keeps counting my characters! Any other suggestions?

0

Can you test my code on its own as a separate php file please?

When you have ran that script open the text file and tell me what you see?

0

ok, your code wrote it to the txt file perfectly but so did mine i added

<?php
$fp = fopen("file.txt","w") or die ("couldn't open!");
fwrite($fp, "blah\n");
fclose($fp);
echo $fp ;
?>

and all that echoed out was resourse id #1 ???

0

In that case something else is counting the number of letters in your code when you are reading the thing back in.

0

Can you test the following as a separate php script and tell me what you see?

<?php
 $filename = "file.txt";
$fp = fopen($filename, "r") or die ("nope");
while (!feof($fp))
{
  $line = fgets($fp, 1024);
  echo "$line<br>";
}
?>

If I am correct it should echo out blah

0

I think it just reads out the file, line by line. To be honest I don't really use php, I just copied that snippet from the net.

Does that mean we can mark this thread as being solved? :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.