Page 1 of 1

Variable Containing HTML

Posted: Fri Jul 23, 2010 6:22 am
by tomnoble
hi,

I am using code to write to a file (this is the line that is of interest),

Code: Select all

$csvdata = $model . ',' . $newcatagory . ',' . $title . ',' . $bodynew . ',' . $amount930 . ',' . $amount900 . ',' . $amount915 . ',' . $amount946 . ',' . $amount960 ."\n";
I am writing it into a plain text format, and then making it into a .csv for by adding a .csv.

I know this is not the most robust way, but its the one I am using.

The problem I have is, $bodynew contains html. So when I put the $bodynew variable into the file I just want it to go in as a string. Where as at the moment if I echo it, or when its get written to the file, it is evaluating the .html. Could I put quotes around it and make it into a single string?

Kind Regards

Tom

Re: Variable Containing HTML

Posted: Fri Jul 23, 2010 11:20 am
by AbraCadaver
You should surround any text in quotes anyway, and that should work, but to force the browser to display it as text you need to tell it:

Code: Select all

header('Content-Type: text/plain');

Re: Variable Containing HTML

Posted: Fri Jul 23, 2010 2:38 pm
by tomnoble
Is there a way I can tell the file that it is plain text as well?

I am currently putting it in quotes via the following method:

Code: Select all

$bodynew = '"'. $body . '"';
Is this correct?

Kind Regards

Tom