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

Recommended Answers

All 10 Replies

Member Avatar for iamthwee

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);
?>

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

Member Avatar for iamthwee

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?

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 ???

Member Avatar for iamthwee

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

Member Avatar for iamthwee

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

ok il have a look thanks

Member Avatar for iamthwee

what happend?

YES! it works but still i do not understand the code :S ... could you explain ?

Member Avatar for iamthwee

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? :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.