- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 TCPDF 库来生成支持阿拉伯字母的 PDF 文件。我创建了一个表并从 MYSQL 数据库中获取数据。
<?php
// Include the main TCPDF library (search for installation path).
require_once('TCPDF/config/tcpdf_config.php');
require_once('TCPDF/tcpdf.php');
class PDF extends TCPDF{
var $tablewidths;
var $headerset;
var $footerset;
function morepagestable($lineheight=8) {
// some things to set and 'remember'
$l = $this->lMargin*2;
$startheight = $h = $this->GetY();
$startpage = $currpage = $this->page;
// calculate the whole width
foreach($this->tablewidths as $width) {
$fullwidth += $width;
}
// Now let's start to write the table
$row = 0;
while($data=mysql_fetch_row($this->results)) {
$this->page = $currpage;
// write the horizontal borders
$this->Line($l,$h,$fullwidth+$l,$h);
// write the content and remember the height of the highest col
foreach($data as $col => $txt) {
$this->page = $currpage;
$this->SetXY($l,$h);
$this->MultiCell($this->tablewidths[$col],$lineheight,$txt,0,$this->colAlign[$col]);
$l += $this->tablewidths[$col];
if($tmpheight[$row.'-'.$this->page] < $this->GetY()) {
$tmpheight[$row.'-'.$this->page] = $this->GetY();
}
if($this->page > $maxpage)
$maxpage = $this->page;
unset($data[$col]);
}
// get the height we were in the last used page
$h = $tmpheight[$row.'-'.$maxpage];
// set the "pointer" to the left margin
$l = $this->lMargin*2;
// set the $currpage to the last page
$currpage = $maxpage;
unset($datas[$row]);
$row++ ;
}
// draw the borders
// we start adding a horizontal line on the last page
$this->page = $maxpage;
$this->Line($l,$h,$fullwidth+$l,$h);
// now we start at the top of the document and walk down
for($i = $startpage; $i <= $maxpage; $i++) {
$this->page = $i;
$l = $this->lMargin*2;
$t = ($i == $startpage) ? $startheight : $this->tMargin;
$lh = ($i == $maxpage) ? $h : $this->h-$this->bMargin;
$this->Line($l,$t,$l,$lh);
foreach($this->tablewidths as $width) {
$l += $width;
$this->Line($l,$t,$l,$lh);
}
}
// set it to the last page, if not it'll cause some problems
$this->page = $maxpage;
}
connect($host='xxxx',$username='xxxx',$passwd='xxxx',$db='xxxxx')
{
$this->conn = mysql_connect($host,$username,$passwd) or die( mysql_error() );
mysql_select_db($db,$this->conn) or die( mysql_error() );
return true;
}
function query($query){
$this->results = mysql_query($query,$this->conn);
$this->numFields = mysql_num_fields($this->results);
}
function mysql_report($query,$dump=false,$attr=array()){
foreach($attr as $key=>$val){
$this->$key = $val ;
}
$this->query($query);
// if column widths not set
if(!isset($this->tablewidths)){
// starting col width
$this->sColWidth = (($this->w-$this->lMargin*2-$this->rMargin))/$this->numFields;
// loop through results header and set initial col widths/ titles/ alignment
// if a col title is less than the starting col width / reduce that column size
for($i=0;$i<$this->numFields;$i++){
$stringWidth = $this->getstringwidth(mysql_field_name($this->results,$i)) + 8 ;
if( ($stringWidth) < $this->sColWidth){
$colFits[$i] = $stringWidth ;
// set any column titles less than the start width to the column title width
}
$this->colTitles[$i] = mysql_field_name($this->results,$i) ;
switch (mysql_field_type($this->results,$i)){
case 'int':
$this->colAlign[$i] = 'L';
break;
default:
$this->colAlign[$i] = 'L';
}
}
// loop through the data, any column whose contents is bigger that the col size is
// resized
while($row=mysql_fetch_row($this->results)){
foreach($colFits as $key=>$val){
$stringWidth = $this->getstringwidth($row[$key]) + 6 ;
if( ($stringWidth) > $this->sColWidth ){
// any col where row is bigger than the start width is now discarded
unset($colFits[$key]);
}else{
// if text is not bigger than the current column width setting enlarge the column
if( ($stringWidth) > $val ){
$colFits[$key] = ($stringWidth) ;
}
}
}
}
foreach($colFits as $key=>$val){
// set fitted columns to smallest size
$this->tablewidths[$key] = $val;
// to work out how much (if any) space has been freed up
$totAlreadyFitted += $val;
}
$surplus = (sizeof($colFits)*$this->sColWidth) - ($totAlreadyFitted);
for($i=0;$i<$this->numFields;$i++){
if(!in_array($i,array_keys($colFits))){
$this->tablewidths[$i] = $this->sColWidth + ($surplus/(($this->numFields)-sizeof($colFits)));
}
}
ksort($this->tablewidths);
if($dump){
Header('Content-type: text/plain');
for($i=0;$i<$this->numFields;$i++){
if(strlen(mysql_field_name($this->results,$i))>$flength){
$flength = strlen(mysql_field_name($this->results,$i));
}
}
switch($this->k){
case 72/25.4:
$unit = 'millimeters';
break;
case 72/2.54:
$unit = 'centimeters';
break;
case 72:
$unit = 'inches';
break;
default:
$unit = 'points';
}
print "All measurements in $unit\n\n";
for($i=0;$i<$this->numFields;$i++){
printf("%-{$flength}s : %-10s : %10f\n",
mysql_field_name($this->results,$i),
mysql_field_type($this->results,$i),
$this->tablewidths[$i] );
}
print "\n\n";
print "\$pdf->tablewidths=\n\tarray(\n\t\t";
for($i=0;$i<$this->numFields;$i++){
($i<($this->numFields-1)) ?
print $this->tablewidths[$i].", /* ".mysql_field_name($this->results,$i)." */ \n\t\t":
print $this->tablewidths[$i]." /* ".mysql_field_name($this->results,$i)." */\n\t\t";
}
print "\n\t);\n";
exit;
}
} else { // end of if tablewidths not defined
for($i=0;$i<$this->numFields;$i++){
$this->colTitles[$i] = mysql_field_name($this->results,$i) ;
switch (mysql_field_type($this->results,$i)){
case 'int':
$this->colAlign[$i] = 'R';
break;
default:
$this->colAlign[$i] = 'L';
}
}
}
mysql_data_seek($this->results,0);
$this->Open();
$this->setY($this->tMargin);
$this->AddPage();
$this->morepagestable($this->FontSizePt);
$this->Output();
}
}
$pdf = new PDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true, 'UTF- 8', false);
$pdf->SetFont('aealarabiya', '', 14, '', false);
$pdf->connect('xxxxxxxxxx','xxxxxxxxxxxxxx','xxxxxxxxxxxxx','xxxxxxxxxxxxx');
$attr=array('titleFontSize'=>24,'titleText'=>'THIS IS MY PDF FILE');
$pdf->mysql_report("SELECT * FROM Student_Table",false,$attr);
?>
我对用我的代码创建的表没意见。检索到的阿拉伯语数据如下?如何解决?
最佳答案
兄弟,你的问题很简单,你需要选择正确的数据库编码并用它进行查询,但在开始之前,我认为我有责任告诉你你不必使用“mysql”你必须使用“mysqli”,现在让我们解决这个问题:
mysqli 连接后执行此操作 $db->set_charset("utf8"); 或者如果您仍然想使用 mysql 使用这个 mysql_set_charset("utf8");
这里是修改后的代码:
connect($host='xxxx',$username='xxxx',$passwd='xxxx',$db='xxxxx')
{
$this->conn = mysql_connect($host,$username,$passwd) or die( mysql_error() );
mysql_select_db($db,$this->conn) or die( mysql_error() );
mysql_set_charset("utf8");
return true;
}
但是,就像我告诉过你的那样,你做错了,使用 mysqli 并用完整的 OOP 来做,不是某个时间,而是其他时间不是!
关于php - 阿拉伯语检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31418844/
我正在使用 Solr 以 3 种语言(阿拉伯语、法语和英语)索引文档,我使用了这个 fieldType :
当我在设备(它的语言是阿拉伯语)中运行我的应用程序时,我感到震惊的是,应该在正确方向的对象会向左移动,反之亦然。 后来我意识到是阿拉伯语本地化的自动布局导致了这个问题。 我以编程方式设置自动布局如下:
我想一个字母一个字母地拆分阿拉伯语单词,将它们涂成不同的颜色并在其上添加事件处理程序。 Image, how it looks like 我实现了关于绘画的部分想法,并处理了辅音字母 (harf),但
我关注 this教程,一切都很好,我预处理和训练我的模型但是当我想找到与以下代码的相似之处时: model = gensim.models.Word2Vec.load("wiki.fa.word2ve
我在使用阿拉伯语文本进行变音符号不敏感搜索时遇到问题。 我已经为相关表格测试了多种设置:utf8 和 utf16 编码以及 utf8_general_ci、utf16_general_ci 和 utf
我正在评估 NLTK 在分析和提取情绪的研究中处理阿拉伯文本的能力。 问题如下: NTLK 是否能够处理并允许分析阿拉伯文本? python 是否能够操作\标记阿拉伯文本? 我能否使用 Python
我正在使用 PHPMailer API 发送电子邮件。我想知道如何用阿拉伯语(非英语)发送主题 $mail->CharSet = 'utf-8'; $array= FetchTable('cos
在过去的 15 天或更长时间里,我一直在为一个奇怪的问题而苦苦挣扎。实际上我有一些阿拉伯语文本,但也有一些英文文本。 MY NAME "some arabic text" "some arabic t
我想用阿拉伯语制作一个 flutter 日期选择器,但有一些变化,这是我的代码: locale: Locale('ar', 'MA'), localizationsDelegates: [
我一直在努力为移动应用程序寻找良好的国际日历支持(包括 Hirji)。我的主要限制是 JVM 是 1.3 并且我们只有 AWT。有一个选项可以转移到另一个为我们提供 SWT 的 JVM,但我似乎找不到
我的应用程序是用英语和阿拉伯语两种不同版本开发的。 我在 iText 中使用 rowspan 和 colspan 创建了 pdf 表格,这在英文版中运行良好,但在阿拉伯语版 rowspan 中不起作用
我想将阿拉伯语单词分割成单个字符。基于直方图/配置文件,我假设我可以通过根据其基线(它具有相似的像素值)剪切/分割字符来进行分割过程。 但是,不幸的是,我仍然坚持构建适当的代码,以使其工作。 % Or
我在 JavaScript 函数中遇到了问题 var tDate = new Intl.DateTimeFormat("ar-US", { day: 'numeric', month: 'lo
我已经编写了 java 代码,我希望在 PdfPTable 上显示阿拉伯文字,该 PdfPTable 被用于 itext 文档以创建 PDF 文档 如附图“???”是阿拉伯代码' PdfPTable
简单地说,有没有支持Lucene.Net的Arabic Analyzer。因为我想索引大量的阿拉伯语 txt 文件。我可以使用标准分析器或空白分析器来解析阿拉伯文文件吗? analyzer = new
我正在使用 Vuejs,我想防止输入标签显示用户的字符并将其替换为我自己的字符(这是一些数字)。 我已经在计算中使用了@onchange 和 Watch 以及 getter 和 setter。问题是字
我正在研究 RTL 功能。我从数据库中获取字符串值作为 (f1 (firstname。但我想要 f1 (firstname) 这是我的 javascript 代码。下面的代码运行良好 EN语言。它不仅
我已经下载了阿拉伯语格式的阿拉伯语语言包和编辑器显示,但是当我纠正一些它不是用正确的方向写它总是从左方向开始,阿拉伯语总是从右方向开始但是这是行不通的.. 我的代码——
我使用的是 3.8.2 版本,插入新记录时,utf8 字符串在数据库中显示为问号 (?),但它会正确显示旧记录(使用 phpmyadmin 插入)。 这是我如何初始化 MySQLPool fun in
我有一个阿拉伯语短信模板,其中包含客户支持号码的占位符,并将占位符替换为实际电话号码(例如 +987654400)。替换时加号 (+) 错位在数字末尾,如 987654400+ 示例代码: >>> >
我是一名优秀的程序员,十分优秀!