We use FPDF to grab data from a database and output to PDF. Some fields in the database contain TeX markup.
Here is the function I came up with in order to search for TeX markup and replace with HTML characters. I only put in the characters that we come across often, as the array could get real large.
function ReplaceTeX($tex)
{
$search = array ("/\\\\\'e/", // Matches \'e
"/\\'e/", // 'e
"/\\\\\`E/",
"/\\\\\'E/",
"/\\\\\`e/",
"/\\\\\'e/",
'/\\\\"a/',
"/\\\\\`a/",
"/\\\\\'a/",
"/\\\\\^a/",
"/\\\\\`i/",
"/\\\\\'i/",
"/\\\\ae/",
"/\\\\AE/",
"/\\\\oe/",
"/\\\\o/",
"/\\\\O/",
"/\\\\\^O/",
'/\\\\"u/',
'/\\\\"o/');
$replace = array (chr(233), //eacute
chr(233), //eacute without slash
chr(200), //E grave
chr(201), //E acute
chr(233), //e grave
chr(234), //e accute
chr(228), //a diaeresis
chr(224), //agrave
chr(225), //aacute
chr(226), //a circumflex
chr(236), //igrave
chr(237), //iacute
chr(230), //aelig
chr(198), //Capital aelig
chr(339), //oe
chr(248), //oslash
chr(216), //capital oslash
chr(212), //capital o circumflex
chr(252), //uuml
chr(246)); //ouml
$texhtml = preg_replace($search, $replace, $tex);
return $texhtml;
}
Then to call the function in FPDF:
$sometext=$pdf->ReplaceTeX($sometext);
Last changed: Jul 06 2009 at 5:55 PM
Back
Comments
Add Comment |