Jump to content

Using HTML within the fwrite[] command


Grazza

Recommended Posts

I am using the following piece of code to write a file

 

$fp = fopen("template.doc", 'w+');

$str = "<html><body><table>

<tr>

<td>$address<br>$address2<br>$address3<br>$town<br>$county<br>$postcode</td>

<td>$name</td>

</tr>

</table>

</body></html>";

fwrite($fp, $str);

fclose($fp);

 

This works fine untill i try to use any HTML like align= or bgcolor or width or any perameters beyond the basics. Does anyone know a way I could get around this? The file I am writing needs to be quite well formated and  must be in a msword file format.

Link to comment
https://forums.phpfreaks.com/topic/94514-using-html-within-the-fwrite-command/
Share on other sites

You are probably using double quotes when using the align= rule... You have to escape them (\") in this case because you use double quotes to define the variable ($var = "something")...

 

You can either use single quotes ($var = 'something') or use the heredoc definition, as so:

 

$var = <<<XYZABC

I can put anything in here i want including single

'

and double

"

quotes. Makes life EASY for stuff like this :D

XYZABC;

 

or

$var = <<<aNyThiNgUniQuE

Yay Flexibility!

aNyThiNgUniQuE;

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.