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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.