<<

. 112
( 132 .)



>>

jpegfile)
placement in a PDF
document
Continued
656 Part V: Appendixes


TABLE F-28 PDF FUNCTIONS (Continued)

Function Return Value Action

int Opens a PNG file and returns
pdf_open_png(int pdf, string
an image for placement in a
pngfile)
PDF document
int Opens a TIFF file and returns
pdf_open_tiff(int pdf, string
an image for placement in a
tifffile)
PDF document
int Opens an image file of the
pdf_open_image_file(int pdf,
given type and returns an
string type, string file, string
image for placement in a
stringparam, int intparam)
PDF document
int Takes an GD image and
pdf_open_memory_image(int pdf,
returns an image for
int image)
placement in a PDF
document
void Closes the PDF image
pdf_close_image(int pdf, int
pdfimage)

void Places an image in the PDF
pdf_place_image(int pdf, int
document
pdfimage, float x, float y,
float scale)

int Returns the width of an
pdf_get_image_width(int pdf,
image
int pdfimage)

int Returns the height of an
pdf_get_image_height(int pdf,
image
int pdfimage)

void Adds a link to a Web
pdf_add_weblink(int pdfdoc,
resource
float llx, float lly, float urx,
float ury, string url)

void Adds a link to a PDF
pdf_add_pdflink(int pdfdoc,
document
float llx, float lly, float urx,
float ury, string filename,
int page, string dest)

void Sets the style of the box
pdf_set_border_style(int pdfdoc,
surrounding all kinds of
string style, float width)
annotations and links
Appendix F: PHP Function Reference 657



Function Return Value Action

void Sets the color of the box
pdf_set_border_color(int pdfdoc,
surrounding all kinds of
float red, float green, float
annotations and links
blue)

void Sets the border-dash style of
pdf_set_border_dash(int pdfdoc,
all kinds of annotations and
float black, float white)
links
int Creates a new PDF object
pdf_new()

int Returns the major version
pdf_get_majorversion()
number of the PDFlib
int Returns the minor version
pdf_get_minorversion()
number of the PDFlib
bool Deletes the PDF object
pdf_delete(int pdfdoc)

int Opens a new PDF document;
pdf_open_file(int pdfdoc
if the file name is NULL, the
[, char filename])
document is created in
memory
int Fetches the full buffer
pdf_get_buffer(int pdfdoc)
containing the generated
PDF data
int Prepares the font fontname
pdf_findfont(int pdfdoc, string
for later use with
fontname, string encoding
[, int embed]) pdf_setfont()

void Sets the current font in the
pdf_setfont(int pdfdoc, int font,
given fontsize
float fontsize)

void Sets complicated dash
pdf_setpolydash(int pdfdoc,
pattern
float darray)

void Concatenates a matrix to
pdf_concat(int pdf, float a,
the current transformation
float b, float c, float d,
matrix for text and graphics
float e, float f)

int Opens an image file with
pdf_open_ccitt(int pdf,
raw CCITT G3“ or
string filename, int width,
G4“compressed bitmap data
int height, int bitreverse,
int k, int blackls1)

Continued
658 Part V: Appendixes


TABLE F-28 PDF FUNCTIONS (Continued)

Function Return Value Action

int Opens an image of the given
pdf_open_image(int pdf, string
type and returns an image
type, string source, string data,
for placement in a PDF
long length, int width, int
document
height, int components, int bpc,
string params)

void Adds a file-attachment
pdf_attach_file(int pdf, float
annotation at the rectangle
lly, float lly, float urx,
specified by the given lower
float ury, string filename,
left-hand and upper right-
string description, string
hand corners
author, string mimetype,
string icon)

void Sets the annotation
pdf_add_note(int pdfdoc, float
llx, float lly, float urx,
float ury, string contents,
string title, string icon,
int open)

void Adds a link annotation to a
pdf_add_locallink(int pdfdoc,
target within the current
float llx, float lly, float
PDF file
urx, float ury, int page,
string dest)

void Adds a launch annotation to
pdf_add_launchlink(int pdfdoc,
a target of arbitrary file type
float llx, float lly, float urx,
float ury, string filename)

void Places a PDF page with the
pdf_place_pdi_page(int pdf, int
lower left-hand corner at
page, float x, float y, float
(x, y) and scales it
sx, float sy)

void Explicitly sets the current
pdf_setmatrix(int pdf, float a,
transformation matrix
float b, float c, float d,
float e, float f)
Appendix G

Regular Expressions
Overview
REGULAR a means for pattern matching in strings. Patterns
EXPRESSIONS PROVIDE
may be as simple as a literal string (like my dog spot) or a literal string with a wild-
card character (like Mr. .* Baggins), or they can grow to be very complex. How
complex? Check out the following example, which is intended to perform email
validation. If you™re new to regular expressions this may look nasty, but to tell the
truth it™s not nearly nasty enough. In fact, to properly validate an email takes about
200 lines of regular expressions.

^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$

When you™re working with PHP and MySQL, three variants of regular expres-
sions exist that you might need to use: the regular PHP regular-expression func-
tions, the Perl-Compatible Regular Expression (PCRE) functions, and MySQL
regular-expression functions. The PHP ereg(), eregi(), ereg_replace(),
eregi_replace(), split(), and spliti() functions use these patterns.
The PCREs are quite different from the standard ereg() functions in places, and
they offer some functionality that can™t be replicated with the ereg() functions.
After you have a good feel for regular expressions, you should probably head over
to http://www.perldoc.com/perl5.6/pod/perlre.html to view some of the dif-
ferences for yourself. The major PCRE functions are preg_match(),
preg_match_all(), and preg_replace().
Finally, another slight variant of the regular expressions used in MySQL exists.
It is described in the Appendix G of the MySQL manual (http://www.mysql.com/
doc/en/Regexp.html).




Literal Patterns
The simplest possible pattern match is to a series of known characters. For instance,
to match jay within a string, you can do the following:

$str = “this is a string with my name: jay”;
if ( ereg(“jay”, $str))
{
659
660 Part V: Appendixes

echo “pattern found”;
}
else
{
echo “string not found”;
}

This tests true and prints pattern found. However, with a simple string like
this, you don™t need a regular expression. One of PHP™s string functions works and
is a good deal faster. For example, in the preceding example, strstr($str,
“jay”) works equally well and is faster.




Characters
In regular expressions you can make use of the following characters.

— \n ” Newline

— \t ” Tab

<<

. 112
( 132 .)



>>