1

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

2 回答 2

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');
于 2013-08-07T13:28:49.213 回答
0

我用这种方式解决了这个问题,例如:

$num=123464;
$char=[
'0'=>'0',
'1'=>'1',
'2'=>'2',
'3'=>'3',
'4'=>'4',
'5'=>'5',
'6'=>'6',
'7'=>'7',
'8'=>'8',
'9'=>'9'];

$num=str_replace(array_keys($char),array_values($char),$num);

在写之前注意这样做你也可以在formatPageNumber中用这种方式转换页脚编号

于 2021-09-13T05:47:27.513 回答