<?php
$data
= array(
          array(
"lastname"=>"Smith", "firstname"=>"Jane", "addl1"=>"123 Main Street", "city"=>"Chicago", "state"=>"Illinois", "zip"=>"12345","phone"=>"(909)888-8888"),
          array(
"lastname"=>"Jones", "firstname"=>"Bob", "addl1"=>"456 E. 7th Ave.", "city"=>"New York City", "state"=>"New York", "zip"=>"11111","phone"=>"(808)777-7777"),
          array(
"lastname"=>"Brown", "firstname"=>"Jane and Joe", "addl1"=>"777 Rose Ave.", "city"=>"Santa Barbara", "state"=>"CA", "zip"=>"00000","phone"=>"(707)666-6666"),
          array(
"lastname"=>"White", "firstname"=>"John", "addl1"=>"1 Park Ave.", "city"=>"New York", "state"=>"NY", "zip"=>"78787-9999","phone"=>"(606)555-5555"),
          array(
"lastname"=>"Black", "firstname"=>"Arthur", "addl1"=>"18 Navin Rd.", "city"=>"Bethel", "state"=>"Pennsylvania", "zip"=>"09090","phone"=>"(505)444-4444"));
    
$out = '
\documentclass{article}
\usepackage{longtable}
\usepackage{fullpage}

\begin{document}
\begin{longtable}{lp{3in}l}
{\bf Name} & {\bf Address} & {\bf Phone} \\\\
\hline\hline \endhead
'
;  

for(
$i=0; $i<count($data);$i++) {
      
$out .= "\\\\\n".$data[$i]['firstname']." ".$data[$i]['lastname']. " & ";
      
$out .= '\begin{minipage}[t]{3in}{\raggedright ';
      
$out .= $data[$i]['addl1'].'\\\\'.$data[$i]['city'].', '.$data[$i]['state'].' '.$data[$i]['zip'].'}\end{minipage} & ';
      
$out .= $data[$i]['phone']."\\\\*\n";
}
$out .= '\end{longtable}\end{document}';
chdir("pdfs");
$texfile = tempnam(".", "pbook");
chmod($texfile, 0644);
$texf = fopen($texfile,"w") or die("Cannot open $texfile");
fputs($texf, $out);
fclose($texf);
rename($texfile, "$texfile.tex");
passthru("pdflatex $texfile > /dev/null ; pdflatex $texfile > /dev/null", $l1);
if(
$l1 == 0) {
  echo
"<script language=\"Javascript\" type=\"text/javascript\">\nlocation.href = \"pdfs/$texfile.pdf\";\n</script>\n";
}
else echo
"Problems....";
?>

1