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

Php 如何更改阿拉伯语和英语的TCPDF中的数字;波斯数字,php,tcpdf,Php,Tcpdf,如何更改TCPDF中阿拉伯和波斯数字的数字,我是否需要更改编码或字符码 我需要将1替换为۱,这是unicode中的阿拉伯语代码 我找到了这个代码,但我不知道如何使用它 function formatPageNumber($num) { $strnum = strval($num); $strnum = preg_replace_callback("/[0-9]/", create_function('$matches', ' $numarr = array("۰", "۱", "۲", "۳",

如何更改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;
}
试试这个:

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');

为什么不使用阿拉伯语字体?这些不是阿拉伯数字,而是波斯数字,在任何阿拉伯字体中都找不到。好的,在这种情况下,请参见下面我的答案。好的,但如果我想写波斯文本,方向被打断。这只是一个示例,您可以将函数只放在需要转换的数字中,类似这样:$html=‘这是我的测试字符串编号’。格式页码('1724');