#native_company# #native_desc#

Using PHP for RTF Page 3

By Sujith Nair
on May 22, 2002

What I
understood from this was:

  1. The whole RTF file is enclosed in braces that is, with in “{” and
  2. “{” is followed by the header part. Basic syntax for it is –
    rtf <charset> deff <fonttbl> <filetbl> <colortbl> <stylesheet>
    <listtables> <revtbl>
  3. Now after the header part, comes the info part. It is embedded in
    “{info” and “}”.
    Within this we have “title”, “author”, “operator” etc.
  4. After the general information comes the data or content, like “{PHP
    for rich text formatpar }”.
Now I was ready to play with RTF. I had to write RTF files on the fly
based an search results
from a database. I thought, it would be easy for me to develop a
template for an RTF file. After
having the template in place I would simply insert the variables before
writing the whole stuff
to an RTF file. I was happy and content. But it didn’t last long. My
clients further demanded
that they should be able to do simple text formatting, on the fly.
Ahm..now what ? I discovered
that formatting in RTF isn’t difficult either. Like for <bold> letter,
all we have to do is insert
“b” before the text you wish to see in bold. But, we have to be careful
about the scope of these
actions. For instance, if I have to see “PHP” of the string “PHP for
rich text format” in bold, all
I have to do is, modify it as:
cgrid {b PHP }{ for rich text format
Again, if I have to make “PHP” bold and red as well, all I will do is
modify it as:
cgrid {bcf6 PHP }{ for rich text format
Here “cf6”
represents red colour. One thing that
is to be taken care of is the scope for every control (viz, b). It
should be well defined within braces.