|
 |
|
เกี่ยวกับการใช้ preg_replace ในการปริ้นท์ออกมาเป็น pdf ครับ |
|
 |
|
|
 |
 |
|
จากโค้ด ผมลอง echo $true อกมาในหน้าปกติไม่ใช่ pdf มันก็ออกถูกต้องนะครับ
คือว่า $friend มันเก็บลง db เป็น ชื่อ."<br>"; อย่างงี้อ่ะครับ สมมติเก็บได้คำว่า นายเหล้าชาว อร่อยดี<br>นายแสงโสม เมานะ<br>
ผมก็ใช้ preg_replace ตัด <br>ออกไป ซึ่งปริ้นท์ปกติก็ออกมา
นายเหล้าชาว อร่อยดี
นายแสงโสม เมานะ
ซึ่งก็ถูกนะครับ แต่พอปริ้นท์เป็น pdf มันกลับไม่ตัด <br> ออกครับ

เนี่ยอ่ะครับผลที่ได้ อยากให้พอเจอคำว่า <br> แล้ว enter เองไปเลยอ่ะครับ ต้องทำยังไง
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP PDF</title>
</head>
<body>
<?php
require('fpdf.php');
define('FPDF_FONTPATH','C:\AppServ\www\travel1\font/');
$objConnect = mssql_connect("PUNN","sa","123456") or die("Error Connect to Database");
$objDB = mssql_select_db("travel");
$strSQL = "SELECT * FROM pre_order where id_pre_order='89'";
$objQuery = mssql_query($strSQL);
$result = mssql_fetch_array($objQuery);
$friend=$result[friend];
$package=$result[package];
$ret = preg_replace(" /[\"\']/", " ", $friend);
$true= stripslashes ($ret);
//echo $true;
class PDF extends FPDF
{
//Page header
function Header()
{
//Page header
global $package;
$this->AddFont('angsana','','angsa.php');
$this->AddFont('angsana','B','angsab.php');
$this->AddFont('angsana','I','angsai.php');
$this->AddFont('angsana','BI','angsaz.php');
$this->SetFont('angsana','',20);
$w=$this->GetStringWidth($package)+6;
$this->SetX((210-$w)/2);
$this->SetDrawColor(0,80,180);
$this->SetFillColor(230,230,0);
$this->SetTextColor(220,50,50);
$this->SetLineWidth(1);
$this->Cell($w,9,$package,1,1,'C',true);
$this->Ln(10);
//Save ordinate
$this->y0=$this->GetY();
}
//Page footer
function Footer()
{
//Position at 1.5 cm from bottom
$this->SetY(-15);
//Arial italic 8
$this->SetFont('Arial','I',8);
//Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
//Instanciation of inherited class
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->AddFont('angsana','','angsa.php');
$pdf->SetFont('angsana','',12);
//*** Insert Text ***//
$pdf->SetX((150-$w)/2);
$pdf->Cell(0,5,$true,0,1);
$pdf->Output("MyPDF.pdf","F");
?>
PDF Created Click <a href="MyPDF.pdf">here</a> to Download
</body>
</html>
Tag : PHP, Ms SQL Server 2005

|
|
 |
 |
 |
 |
Date :
2010-10-28 10:40:03 |
By :
เด็กโง่ |
View :
1187 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ function
<?
function br2nl($string)
{
return preg_replace('/\<br(\s*)?\/?\>/i', "\n", $string);
}
$package="<br>1<br>2<br>3";
$package=br2nl($package);
?>
|
ประวัติการแก้ไข 2010-10-28 16:04:36
 |
 |
 |
 |
Date :
2010-10-28 16:04:02 |
By :
dekkuza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|