Variable Containing HTML

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
tomnoble
Forum Commoner
Posts: 28
Joined: Tue Jun 15, 2010 1:18 pm

Variable Containing HTML

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Variable Containing HTML

Post 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');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
tomnoble
Forum Commoner
Posts: 28
Joined: Tue Jun 15, 2010 1:18 pm

Re: Variable Containing HTML

Post 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
Post Reply