如何更改TCPDF中的阿拉伯语和数字波斯数字,我需要更改编码或字符代码吗?
我需要将1
替换为۱
,这是unicode中的阿拉伯语代码。
我找到了这段代码,但我不知道如何使用它
function formatPageNumber($num) {
$strnum = strval($num);
$strnum = preg_replace_callback("/[0-9]/", create_function('$matches', '
$numarr = array("۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹");
return $numarr[intval($matches[0])];'), $strnum);
return $strnum;
}
答案 0 :(得分:2)
试试这个:
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
function formatPageNumber($num) {
$strnum = strval($num);
$strnum = preg_replace_callback("/[0-9]/", create_function('$matches', '
$numarr = array("۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹");
return $numarr[intval($matches[0])];'), $strnum);
return $strnum;
}
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set font
$pdf->SetFont('dejavusans', '', 10);
// add a page
$pdf->AddPage();
// define some HTML content with style
$html = formatPageNumber("This is my test string number 1724");
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// reset pointer to the last page
$pdf->lastPage();
//Close and output PDF document
$pdf->Output('test.pdf', 'I');