如何更改TCPDF中阿拉伯语和数字的数量波斯数字

时间:2013-08-07 11:49:46

标签: php tcpdf

如何更改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;
}

1 个答案:

答案 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');
相关问题