RSS Banner


W32api functions

Posted by: admin  /  Category: PHP

Introduction

This extension is a generic extension API to DLLs. This was originally written to allow access to the Win32 API from PHP, although you can also access other functions exported via other DLLs.

Currently supported types are generic PHP types (strings, booleans, floats, integers and nulls) and types you define with w32api_deftype().

This extension will only work on Windows systems.

Installation

There is no installation needed to use these functions; they are part of the PHP core.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

This extension defines one resource type, used for user defined types. The name of this resource is “dynaparm”.

Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

DC_MICROSOFT (integer)
DC_BORLAND (integer)
DC_CALL_CDECL (integer)
DC_CALL_STD (integer)
DC_RETVAL_MATH4 (integer)
DC_RETVAL_MATH8 (integer)
DC_CALL_STD_BO (integer)
DC_CALL_STD_MS (integer)
DC_CALL_STD_M8 (integer)
DC_FLAG_ARGPTR (integer)

Examples

This example gets the amount of time the system has been running and displays it in a message box.

Example 1. Get the uptime and display it in a message box

<?php
// Define constants needed, taken from
// Visual Studio/Tools/Winapi/WIN32API.txt
define("MB_OK", 0);

// Load the extension in
dl("php_w32api.dll");

// Register the GetTickCount function from kernel32.dll
w32api_register_function("kernel32.dll",
"GetTickCount",
"long");

// Register the MessageBoxA function from User32.dll
w32api_register_function("User32.dll",
"MessageBoxA",
"long");

// Get uptime information
$ticks = GetTickCount();

// Convert it to a nicely displayable text
$secs  = floor($ticks / 1000);
$mins  = floor($secs / 60);
$hours = floor($mins / 60);

$str = sprintf("You have been using your computer for:".
"\r\n %d Milliseconds, or \r\n %d Seconds".
"or \r\n %d mins or\r\n %d hours %d mins.",
$ticks,
$secs,
$mins,
$hours,
$mins - ($hours*60));

// Display a message box with only an OK button and the uptime text
MessageBoxA(NULL,
$str,
"Uptime Information",
MB_OK);
?>
Table of Contents
w32api_deftype – Defines a type for use with other w32api_functions
w32api_init_dtype –  Creates an instance of the data type typename and fills it with the values passed
w32api_invoke_function – Invokes function funcname with the arguments passed after the function name
w32api_register_function – Registers function function_name from library with PHP
w32api_set_call_method – Sets the calling method used

WDDX Functions

Posted by: admin  /  Category: PHP

Introduction

These functions are intended for work with WDDX.

Requirements

In order to use WDDX, you will need to install the expat library (which comes with Apache 1.3.7 or higher).

Installation

After installing expat compile PHP with –enable-wddx.

The windows version of PHP has built in support for this extension. You do not need to load any additional extension in order to use these functions.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

This extension has no resource types defined.

Predefined Constants

This extension has no constants defined.

Examples

All the functions that serialize variables use the first element of an array to determine whether the array is to be serialized into an array or structure. If the first element has string key, then it is serialized into a structure, otherwise, into an array.

Example 1. Serializing a single value

<?php
print wddx_serialize_value("PHP to WDDX packet example", "PHP packet");
?>

This example will produce:

<wddxPacket version='1.0'><header comment='PHP packet'/><data>
<string>PHP to WDDX packet example</string></data></wddxPacket>
Example 2. Using incremental packets

<?php
$pi = 3.1415926;
$packet_id = wddx_packet_start("PHP");
wddx_add_vars($packet_id, "pi");

/* Suppose $cities came from database */
$cities = array("Austin", "Novato", "Seattle");
wddx_add_vars($packet_id, "cities");

$packet = wddx_packet_end($packet_id);
print $packet;
?>

This example will produce:

<wddxPacket version='1.0'><header comment='PHP'/><data><struct>
<var name='pi'><number>3.1415926</number></var><var name='cities'>
<array length='3'><string>Austin</string><string>Novato</string>
<string>Seattle</string></array></var></struct></data></wddxPacket>

Note: If you want to serialize non-ASCII characters you have to set the appropriate locale before doing so (see setlocale()).

Table of Contents
wddx_add_vars –  Add variables to a WDDX packet with the specified ID
wddx_deserialize – Deserializes a WDDX packet
wddx_packet_end – Ends a WDDX packet with the specified ID
wddx_packet_start –  Starts a new WDDX packet with structure inside it
wddx_serialize_value – Serialize a single value into a WDDX packet
wddx_serialize_vars – Serialize variables into a WDDX packet

XML parser functions

Posted by: admin  /  Category: PHP

Introduction

XML (eXtensible Markup Language) is a data format for structured document interchange on the Web. It is a standard defined by The World Wide Web consortium (W3C). Information about XML and related technologies can be found at http://www.w3.org/XML/.

This PHP extension implements support for James Clark’s expat in PHP. This toolkit lets you parse, but not validate, XML documents. It supports three source character encodings also provided by PHP: US-ASCII, ISO-8859-1 and UTF-8. UTF-16 is not supported.

This extension lets you create XML parsers and then define handlers for different XML events. Each XML parser also has a few parameters you can adjust.

Requirements

This extension uses expat, which can be found at http://www.jclark.com/xml/expat.html. The Makefile that comes with expat does not build a library by default, you can use this make rule for that:

libexpat.a: $(OBJS)
ar -rc $@ $(OBJS)
ranlib $@

A source RPM package of expat can be found at http://sourceforge.net/projects/expat/.

Installation

These functions are enabled by default, using the bundled expat library. You can disable XML support with –disable-xml. If you compile PHP as a module for Apache 1.3.9 or later, PHP will automatically use the bundled expat library from Apache. In order you dont’t want to use the bundled expat library configure PHP –with-expat-dir=DIR, where DIR should point to the base installation directory of expat.

The windows version of PHP has built in support for this extension. You do not need to load any additional extension in order to use these functions.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

xml

The xml resource as returned by xml_parser_create() and xml_parser_create_ns() references an xml parser instance to be used with the functions provided by this extension.

Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

XML_ERROR_NONE (integer)
XML_ERROR_NO_MEMORY (integer)
XML_ERROR_SYNTAX (integer)
XML_ERROR_NO_ELEMENTS (integer)
XML_ERROR_INVALID_TOKEN (integer)
XML_ERROR_UNCLOSED_TOKEN (integer)
XML_ERROR_PARTIAL_CHAR (integer)
XML_ERROR_TAG_MISMATCH (integer)
XML_ERROR_DUPLICATE_ATTRIBUTE (integer)
XML_ERROR_JUNK_AFTER_DOC_ELEMENT (integer)
XML_ERROR_PARAM_ENTITY_REF (integer)
XML_ERROR_UNDEFINED_ENTITY (integer)
XML_ERROR_RECURSIVE_ENTITY_REF (integer)
XML_ERROR_ASYNC_ENTITY (integer)
XML_ERROR_BAD_CHAR_REF (integer)
XML_ERROR_BINARY_ENTITY_REF (integer)
XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF (integer)
XML_ERROR_MISPLACED_XML_PI (integer)
XML_ERROR_UNKNOWN_ENCODING (integer)
XML_ERROR_INCORRECT_ENCODING (integer)
XML_ERROR_UNCLOSED_CDATA_SECTION (integer)
XML_ERROR_EXTERNAL_ENTITY_HANDLING (integer)
XML_OPTION_CASE_FOLDING (integer)
XML_OPTION_TARGET_ENCODING (integer)
XML_OPTION_SKIP_TAGSTART (integer)
XML_OPTION_SKIP_WHITE (integer)

Event Handlers

The XML event handlers defined are:

Table 1. Supported XML handlers

PHP function to set handler Event description
xml_set_element_handler() Element events are issued whenever the XML parser encounters start or end tags. There are separate handlers for start tags and end tags.
xml_set_character_data_handler() Character data is roughly all the non-markup contents of XML documents, including whitespace between tags. Note that the XML parser does not add or remove any whitespace, it is up to the application (you) to decide whether whitespace is significant.
xml_set_processing_instruction_handler() PHP programmers should be familiar with processing instructions (PIs) already. <?php ?> is a processing instruction, where php is called the “PI target”. The handling of these are application-specific, except that all PI targets starting with “XML” are reserved.
xml_set_default_handler() What goes not to another handler goes to the default handler. You will get things like the XML and document type declarations in the default handler.
xml_set_unparsed_entity_decl_handler() This handler will be called for declaration of an unparsed (NDATA) entity.
xml_set_notation_decl_handler() This handler is called for declaration of a notation.
xml_set_external_entity_ref_handler() This handler is called when the XML parser finds a reference to an external parsed general entity. This can be a reference to a file or URL, for example. See the external entity example for a demonstration.

Case Folding

The element handler functions may get their element names case-folded. Case-folding is defined by the XML standard as “a process applied to a sequence of characters, in which those identified as non-uppercase are replaced by their uppercase equivalents”. In other words, when it comes to XML, case-folding simply means uppercasing.

By default, all the element names that are passed to the handler functions are case-folded. This behaviour can be queried and controlled per XML parser with the xml_parser_get_option() and xml_parser_set_option() functions, respectively.

Error Codes

The following constants are defined for XML error codes (as returned by xml_parse()):

XML_ERROR_NONE
XML_ERROR_NO_MEMORY
XML_ERROR_SYNTAX
XML_ERROR_NO_ELEMENTS
XML_ERROR_INVALID_TOKEN
XML_ERROR_UNCLOSED_TOKEN
XML_ERROR_PARTIAL_CHAR
XML_ERROR_TAG_MISMATCH
XML_ERROR_DUPLICATE_ATTRIBUTE
XML_ERROR_JUNK_AFTER_DOC_ELEMENT
XML_ERROR_PARAM_ENTITY_REF
XML_ERROR_UNDEFINED_ENTITY
XML_ERROR_RECURSIVE_ENTITY_REF
XML_ERROR_ASYNC_ENTITY
XML_ERROR_BAD_CHAR_REF
XML_ERROR_BINARY_ENTITY_REF
XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF
XML_ERROR_MISPLACED_XML_PI
XML_ERROR_UNKNOWN_ENCODING
XML_ERROR_INCORRECT_ENCODING
XML_ERROR_UNCLOSED_CDATA_SECTION
XML_ERROR_EXTERNAL_ENTITY_HANDLING

Character Encoding

PHP’s XML extension supports the Unicode character set through different character encodings. There are two types of character encodings, source encoding and target encoding. PHP’s internal representation of the document is always encoded with UTF-8.

Source encoding is done when an XML document is parsed. Upon creating an XML parser, a source encoding can be specified (this encoding can not be changed later in the XML parser’s lifetime). The supported source encodings are ISO-8859-1, US-ASCII and UTF-8. The former two are single-byte encodings, which means that each character is represented by a single byte. UTF-8 can encode characters composed by a variable number of bits (up to 21) in one to four bytes. The default source encoding used by PHP is ISO-8859-1.

Target encoding is done when PHP passes data to XML handler functions. When an XML parser is created, the target encoding is set to the same as the source encoding, but this may be changed at any point. The target encoding will affect character data as well as tag names and processing instruction targets.

If the XML parser encounters characters outside the range that its source encoding is capable of representing, it will return an error.

If PHP encounters characters in the parsed XML document that can not be represented in the chosen target encoding, the problem characters will be “demoted”. Currently, this means that such characters are replaced by a question mark.

Examples

Here are some example PHP scripts parsing XML documents.

XML Element Structure Example

This first example displays the stucture of the start elements in a document with indentation.

Example 1. Show XML Element Structure

$file = "data.xml";
$depth = array();

function startElement($parser, $name, $attrs) {
global $depth;
for ($i = 0; $i < $depth[$parser]; $i++) {
print "  ";
}
print "$name\n";
$depth[$parser]++;
}

function endElement($parser, $name) {
global $depth;
$depth[$parser]--;
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}

while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);

XML Tag Mapping Example

Example 2. Map XML to HTML

This example maps tags in an XML document directly to HTML tags. Elements not found in the “map array” are ignored. Of course, this example will only work with a specific XML document type.

$file = "data.xml";
$map_array = array(
"BOLD"     => "B",
"EMPHASIS" => "I",
"LITERAL"  => "TT"
);

function startElement($parser, $name, $attrs) {
global $map_array;
if ($htmltag = $map_array[$name]) {
print "<$htmltag>";
}
}

function endElement($parser, $name) {
global $map_array;
if ($htmltag = $map_array[$name]) {
print "</$htmltag>";
}
}

function characterData($parser, $data) {
print $data;
}

$xml_parser = xml_parser_create();
// use case-folding so we are sure to find the tag in $map_array
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}

while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);

XML External Entity Example

This example highlights XML code. It illustrates how to use an external entity reference handler to include and parse other documents, as well as how PIs can be processed, and a way of determining “trust” for PIs containing code.

XML documents that can be used for this example are found below the example (xmltest.xml and xmltest2.xml.)

Example 3. External Entity Example

<?php
$file = "xmltest.xml";

function trustedFile($file) {
// only trust local files owned by ourselves
if (!eregi("^([a-z]+)://", $file)
&& fileowner($file) == getmyuid()) {
return true;
}
return false;
}

function startElement($parser, $name, $attribs) {
print "&lt;<font color=\"#0000cc\">$name</font>";
if (sizeof($attribs)) {
while (list($k, $v) = each($attribs)) {
print " <font color=\"#009900\">$k</font>=\"<font
color=\"#990000\">$v</font>\"";
}
}
print "&gt;";
}

function endElement($parser, $name) {
print "&lt;/<font color=\"#0000cc\">$name</font>&gt;";
}

function characterData($parser, $data) {
print "<b>$data</b>";
}

function PIHandler($parser, $target, $data) {
switch (strtolower($target)) {
case "php":
global $parser_file;
// If the parsed document is "trusted", we say it is safe
// to execute PHP code inside it.  If not, display the code
// instead.
if (trustedFile($parser_file[$parser])) {
eval($data);
} else {
printf("Untrusted PHP code: <i>%s</i>",
htmlspecialchars($data));
}
break;
}
}

function defaultHandler($parser, $data) {
if (substr($data, 0, 1) == "&" && substr($data, -1, 1) == ";") {
printf('<font color="#aa00aa">%s</font>',
htmlspecialchars($data));
} else {
printf('<font size="-1">%s</font>',
htmlspecialchars($data));
}
}

function externalEntityRefHandler($parser, $openEntityNames, $base, $systemId,
$publicId) {
if ($systemId) {
if (!list($parser, $fp) = new_xml_parser($systemId)) {
printf("Could not open entity %s at %s\n", $openEntityNames,
$systemId);
return false;
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($parser, $data, feof($fp))) {
printf("XML error: %s at line %d while parsing entity %s\n",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser), $openEntityNames);
xml_parser_free($parser);
return false;
}
}
xml_parser_free($parser);
return true;
}
return false;
}

function new_xml_parser($file) {
global $parser_file;

$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_set_processing_instruction_handler($xml_parser, "PIHandler");
xml_set_default_handler($xml_parser, "defaultHandler");
xml_set_external_entity_ref_handler($xml_parser, "externalEntityRefHandler");

if (!($fp = @fopen($file, "r"))) {
return false;
}
if (!is_array($parser_file)) {
settype($parser_file, "array");
}
$parser_file[$xml_parser] = $file;
return array($xml_parser, $fp);
}

if (!(list($xml_parser, $fp) = new_xml_parser($file))) {
die("could not open XML input");
}

print "<pre>";
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
print "</pre>";
print "parse complete\n";
xml_parser_free($xml_parser);

?>
Example 4. xmltest.xml

<?xml version='1.0'?>
<!DOCTYPE chapter SYSTEM "/just/a/test.dtd" [
<!ENTITY plainEntity "FOO entity">
<!ENTITY systemEntity SYSTEM "xmltest2.xml">
]>
<chapter>
<TITLE>Title &plainEntity;</TITLE>
<para>
<informaltable>
<tgroup cols="3">
<tbody>
<row><entry>a1</entry><entry morerows="1">b1</entry><entry>c1</entry></row>
<row><entry>a2</entry><entry>c2</entry></row>
<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
</tbody>
</tgroup>
</informaltable>
</para>
&systemEntity;
<section id="about">
<title>About this Document</title>
<para>
<!-- this is a comment -->
<?php print 'Hi!  This is PHP version '.phpversion(); ?>
</para>
</section>
</chapter>

This file is included from xmltest.xml:

Example 5. xmltest2.xml

<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY testEnt "test entity">
]>
<foo>
<element attrib="value"/>
&testEnt;
<?php print "This is some more PHP code being executed."; ?>
</foo>
Table of Contents
utf8_decode –  Converts a string with ISO-8859-1 characters encoded with UTF-8 to single-byte ISO-8859-1.
utf8_encode – encodes an ISO-8859-1 string to UTF-8
xml_error_string – get XML parser error string
xml_get_current_byte_index – get current byte index for an XML parser
xml_get_current_column_number –  Get current column number for an XML parser
xml_get_current_line_number – get current line number for an XML parser
xml_get_error_code – get XML parser error code
xml_parse_into_struct – Parse XML data into an array structure
xml_parse – start parsing an XML document
xml_parser_create_ns –  Create an XML parser
xml_parser_create – create an XML parser
xml_parser_free – Free an XML parser
xml_parser_get_option – get options from an XML parser
xml_parser_set_option – set options in an XML parser
xml_set_character_data_handler – set up character data handler
xml_set_default_handler – set up default handler
xml_set_element_handler – set up start and end element handlers
xml_set_end_namespace_decl_handler –  Set up character data handler
xml_set_external_entity_ref_handler – set up external entity reference handler
xml_set_notation_decl_handler – set up notation declaration handler
xml_set_object – Use XML Parser within an object
xml_set_processing_instruction_handler –  Set up processing instruction (PI) handler
xml_set_start_namespace_decl_handler –  Set up character data handler
xml_set_unparsed_entity_decl_handler –  Set up unparsed entity declaration handler

XML-RPC functions

Posted by: admin  /  Category: PHP

Introduction

These functions can be used to write XML-RPC servers and clients. You can find more information about XML-RPC at http://www.xmlrpc.com/, and more documentation on this extension and it’s functions at http://xmlrpc-epi.sourceforge.net/.

Warning
This extension is EXPERIMENTAL. The behaviour of this extension — including the names of its functions and anything else documented about this extension — may change without notice in a future release of PHP. Use this extension at your own risk.

Requirements

No external libraries are needed to build this extension.

Installation

XML-RPC support in PHP is not enabled by default. You will need to use the –with-xmlrpc[=DIR] configuration option when compiling PHP to enable XML-RPC support. This extension is bundled into PHP as of 4.1.0.

Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

Table 1. XML-RPC configuration options

Name Default Changeable
xmlrpc_errors “0″ PHP_INI_SYSTEM
xmlrpc_error_number “0″ PHP_INI_ALL

For further details and definition of the PHP_INI_* constants see ini_set().

Resource Types

This extension has no resource types defined.

Predefined Constants

This extension has no constants defined.

Table of Contents
xmlrpc_decode_request – Decodes XML into native PHP types
xmlrpc_decode – Decodes XML into native PHP types
xmlrpc_encode_request – Generates XML for a method request
xmlrpc_encode – Generates XML for a PHP value
xmlrpc_get_type – Gets xmlrpc type for a PHP value. Especially useful for base64 and datetime strings
xmlrpc_parse_method_descriptions – Decodes XML into a list of method descriptions
xmlrpc_server_add_introspection_data – Adds introspection documentation
xmlrpc_server_call_method – Parses XML requests and call methods
xmlrpc_server_create – Creates an xmlrpc server
xmlrpc_server_destroy – Destroys server resources
xmlrpc_server_register_introspection_callback – Register a PHP function to generate documentation
xmlrpc_server_register_method – Register a PHP function to resource method matching method_name
xmlrpc_set_type – Sets xmlrpc type, base64 or datetime, for a PHP string value

XSLT functions

Posted by: admin  /  Category: PHP

Introduction

This PHP extension provides a processor independent API to XSLT transformations. Currently this extension only supports the Sablotron library from the Ginger Alliance. Support is planned for other libraries, such as the Xalan library or the libxslt library.

XSLT (Extensible Stylesheet Language (XSL) Transformations) is a language for transforming XML documents into other XML documents. It is a standard defined by The World Wide Web Consortium (W3C). Information about XSLT and related technologies can be found at http://www.w3.org/TR/xslt.

Note: This extension is different than the sablotron extension distributed with versions of PHP prior to PHP 4.1, currently only the new XSLT extension in PHP 4.1 is supported. If you need support for the old extension, please ask your questions on the PHP mailing lists.

Requirements

This extension uses Sablotron and expat, which can both be found at http://www.gingerall.com/. Binaries are provided as well as source.

Installation

On UNIX, run configure with the –enable-xslt –with-xslt-sablot options. The Sablotron library should be installed somewhere your compiler can find it.

Make sure you have the same libraries linked to the Sablotron library as those, which are linked with PHP. The configuration options: –with-expat-dir=DIR –with-iconv-dir=DIR are there to help you specify them. When asking for support, always mention these directives, and whether there are other versions of those libraries installed on your system somewhere. Naturally, provide all the version numbers.

JavaScript E-XSLT support: If you compiled Sablotron with JavaScript support, you must specify the option: –with-sablot-js=DIR.

Note to Win32 Users: In order to enable this module on a Windows environment, you must copy sablot.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32)

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

This extension has no resource types defined.

Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

XSLT_OPT_SILENT (integer)
Drop all logging and error reporting. This is a generic option for all backends that may be added in the future.

XSLT_SABOPT_PARSE_PUBLIC_ENTITIES (integer)
Tell Sablotron to parse public entities. By default this has been turned off.

XSLT_SABOPT_DISABLE_ADDING_META (integer)
Do not add the meta tag “Content-Type” for HTML output. The default is set during compilation of Sablotron.

XSLT_SABOPT_DISABLE_STRIPPING (integer)
Suppress the whitespace stripping (on data files only).

XSLT_SABOPT_IGNORE_DOC_NOT_FOUND (integer)
Consider unresolved documents (the document() function) non-lethal.

XSLT_ERR_UNSUPPORTED_SCHEME (integer)
Error return code, for scheme handlers.

Table of Contents
xslt_create – Create a new XSLT processor
xslt_errno – Return a error number
xslt_error – Return a error string
xslt_free – Free XSLT processor
xslt_process – Perform an XSLT transformation
xslt_set_base – Set the base URI for all XSLT transformations
xslt_set_encoding – Set the encoding for the parsing of XML documents
xslt_set_error_handler – Set an error handler for a XSLT processor
xslt_set_log – Set the log file to write log messages to
xslt_set_sax_handler – Set SAX handlers for a XSLT processor
xslt_set_sax_handlers –  Set the SAX handlers to be called when the XML document gets processed
xslt_set_scheme_handler – Set Scheme handlers for a XSLT processor
xslt_set_scheme_handlers –  Set the scheme handlers for the XSLT processor

YAZ functions

Posted by: admin  /  Category: PHP

Introduction

This extension offers a PHP interface to the YAZ toolkit that implements the Z39.50 Protocol for Information Retrieval. With this extension you can easily implement a Z39.50 origin (client) that searches or scans Z39.50 targets (servers) in parallel.

The module hides most of the complexity of Z39.50 so it should be fairly easy to use. It supports persistent stateless connections very similar to those offered by the various RDB APIs that are available for PHP. This means that sessions are stateless but shared amongst users, thus saving the connect and initialize phase steps in most cases.

YAZ is available at http://www.indexdata.dk/yaz/. You can find news information, example scripts, etc. for this extension at http://www.indexdata.dk/phpyaz/.

Installation

Compile YAZ (ANSI/NISO Z39.50 support) and install it. Build PHP with your favourite modules and add option –with-yaz[=DIR]. Your task is roughly the following:

gunzip -c php-4.3.X.tar.gz|tar xf -
gunzip -c yaz-2.0.tar.gz|tar xf -
cd yaz-2.0
./configure --prefix=/usr
make
make install
cd ../php-4.3.X.
./configure --with-yaz=/usr/bin
make
make install

If you are using YAZ as a shared extension, add (or uncomment) the following line in php.ini on Unix:

extension=php_yaz.so

And for Windows:

extension=php_yaz.dll

On windows, php_yaz.dll depend on yaz.dll. You’ll find yaz.dll in sub directory dlls in the Win32 zip archive. Copy yaz.dll to a directory in your PATH environment (c:\winnt\system32 or c:\windows\system32).

Warning
The IMAP extension cannot be used in conjuction with the recode or YAZ extensions. This is due to the fact that they both share the same internal symbol.

Note: The above problem is solved in version 2.0 of YAZ.

Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

Table 1. YAZ configuration options

Name Default Changeable
yaz.max_links “100″ PHP_INI_ALL
yaz.log_file “” PHP_INI_ALL

For further details and definition of the PHP_INI_* constants see ini_set().

Resource Types

This extension has no resource types defined.

Predefined Constants

This extension has no constants defined.

Examples

PHP/YAZ keeps track of connections with targets (Z-Associations). A resource represents a connection to a target.

The script below demonstrates the parallel searching feature of the API. When invoked with no arguments it prints a query form; else (arguments are supplied) it searches the targets as given in array host.

Example 1. Parallel searching using Yaz

$num_hosts = count ($host);
if (empty($term) || count($host) == 0) {
echo '<form method="get">
<input type="checkbox"
name="host[]" value="bagel.indexdata.dk/gils">
GILS test
<input type="checkbox"
name="host[]" value="localhost:9999/Default">
local test
<input type="checkbox" checked="1"
name="host[]" value="z3950.loc.gov:7090/voyager">
Library of Congress
<br>
RPN Query:
<input type="text" size="30" name="term">
<input type="submit" name="action" value="Search">
';
} else {
echo 'You searced for ' . htmlspecialchars($term) . '<br>';
for ($i = 0; $i < $num_hosts; $i++) {
$id[] = yaz_connect($host[$i]);
yaz_range($id[$i], 1, 10);
yaz_search($id[$i],"rpn",$term);
}
yaz_wait();
for ($i = 0; $i < $num_hosts; $i++) {
echo '<hr>' . $host[$i] . ":";
$error = yaz_error($id[$i]);
if (!empty($error)) {
echo "Error: $error";
} else {
$hits = yaz_hits($id[$i]);
echo "Result Count $hits";
}
echo '<dl>';
for ($p = 1; $p <= 10; $p++) {
$rec = yaz_record($id[$i],$p,"string");
if (empty($rec)) continue;
echo "<dt><b>$p</b></dt><dd>";
echo ereg_replace("\n", "<br>\n",$rec);
echo "</dd>";
}
echo '</dl>';
}
}
Table of Contents
yaz_addinfo – Returns additional error information
yaz_ccl_conf – Configure CCL parser
yaz_ccl_parse – Invoke CCL Parser
yaz_close – Close YAZ connection
yaz_connect –  Prepares for a connection to a Z39.50 target (server).
yaz_database –  Specifies the databases within a session
yaz_element –  Specifies Element-Set Name for retrieval
yaz_errno – Returns error number
yaz_error – Returns error description
yaz_get_option – Returns value of option for connection
yaz_hits – Returns number of hits for last search
yaz_itemorder –  Prepares for Z39.50 Item Order with an ILL-Request package
yaz_present –  Prepares for retrieval (Z39.50 present).
yaz_range –  Specifies the maximum number of records to retrieve
yaz_record – Returns a record
yaz_scan_result – Returns Scan Response result
yaz_scan – Prepares for a scan
yaz_schema –  Specifies schema for retrieval.
yaz_search – Prepares for a search
yaz_set_option – Sets one or more options for connection
yaz_sort – Sets sorting criteria
yaz_syntax –  Specifies the preferred record syntax for retrieval.
yaz_wait – Wait for Z39.50 requests to complete

YP/NIS Functions

Posted by: admin  /  Category: PHP

Introduction

NIS (formerly called Yellow Pages) allows network management of important administrative files (e.g. the password file). For more information refer to the NIS manpage and The Linux NIS(YP)/NYS/NIS+ HOWTO. There is also a book called Managing NFS and NIS by Hal Stern.

Note: This extension is not available on Windows platforms.

Requirements

None besides functions from standard Unix libraries which are always available (either libc or libnsl, configure will detect which one to use).

Installation

To get these functions to work, you have to configure PHP with –enable-yp.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

YPERR_BADARGS (integer)
YPERR_BADDB (integer)
YPERR_BUSY (integer)
YPERR_DOMAIN (integer)
YPERR_KEY (integer)
YPERR_MAP (integer)
YPERR_NODOM (integer)
YPERR_NOMORE (integer)
YPERR_PMAP (integer)
YPERR_RESRC (integer)
YPERR_RPC (integer)
YPERR_YPBIND (integer)
YPERR_YPERR (integer)
YPERR_YPSERV (integer)
YPERR_VERS (integer)
Table of Contents
yp_all –  Traverse the map and call a function on each entry
yp_cat –  Return an array containing the entire map
yp_err_string –  Returns the error string associated with the previous operation
yp_errno –  Returns the error code of the previous operation
yp_first –  Returns the first key-value pair from the named map
yp_get_default_domain – Fetches the machine’s default NIS domain
yp_master –  Returns the machine name of the master NIS server for a map
yp_match – Returns the matched line
yp_next – Returns the next key-value pair in the named map.
yp_order – Returns the order number for a map

Zip File Functions (Read Only Access)

Posted by: admin  /  Category: PHP

Introduction

This module enables you to transparently read ZIP compressed archives and the files inside them.

Requirements

This module uses the functions of the ZZIPlib library by Guido Draheim. You need ZZIPlib version >= 0.10.6.

Note that ZZIPlib only provides a subset of functions provided in a full implementation of the ZIP compression algorithm and can only read ZIP file archives. A normal ZIP utility is needed to create the ZIP file archives read by this library.

Installation

Zip support in PHP is not enabled by default. You will need to use the –with-zip[=DIR] configuration option when compiling PHP to enable zip support.

Note: Zip support before PHP 4.1.0 is experimental. This section reflects the Zip extension as it exists in PHP 4.1.0 and later.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

This extension has no resource types defined.

Predefined Constants

This extension has no constants defined.

Examples

This example opens a ZIP file archive, reads each file in the archive and prints out its contents. The test2.zip archive used in this example is one of the test archives in the ZZIPlib source distribution.

Example 1. Zip Usage Example

<?php

$zip = zip_open("/tmp/test2.zip");

if ($zip) {

while ($zip_entry = zip_read($zip)) {
echo "Name:               " . zip_entry_name($zip_entry) . "\n";
echo "Actual Filesize:    " . zip_entry_filesize($zip_entry) . "\n";
echo "Compressed Size:    " . zip_entry_compressedsize($zip_entry) . "\n";
echo "Compression Method: " . zip_entry_compressionmethod($zip_entry) . "\n";

if (zip_entry_open($zip, $zip_entry, "r")) {
echo "File Contents:\n";
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
echo "$buf\n";

zip_entry_close($zip_entry);
}
echo "\n";

}

zip_close($zip);

}

?>
Table of Contents
zip_close – Close a Zip File Archive
zip_entry_close – Close a Directory Entry
zip_entry_compressedsize – Retrieve the Compressed Size of a Directory Entry
zip_entry_compressionmethod – Retrieve the Compression Method of a Directory Entry
zip_entry_filesize – Retrieve the Actual File Size of a Directory Entry
zip_entry_name – Retrieve the Name of a Directory Entry
zip_entry_open – Open a Directory Entry for Reading
zip_entry_read – Read From an Open Directory Entry
zip_open – Open a Zip File Archive
zip_read – Read Next Entry in a Zip File Archive

Zlib Compression Functions

Posted by: admin  /  Category: PHP

Introduction

This module enables you to transparently read and write gzip (.gz) compressed files, through versions of most of the filesystem functions which work with gzip-compressed files (and uncompressed files, too, but not with sockets).

Note: Version 4.0.4 introduced a fopen-wrapper for .gz-files, so that you can use a special ‘zlib:’ URL to access compressed files transparently using the normal f*() file access functions if you prepend the filename or path with a ‘zlib:’ prefix when calling fopen().

In version 4.3.0, this special prefix has been changed to ‘zlib://’ to prevent ambiguities with filenames containing ‘:’.

This feature requires a C runtime library that provides the fopencookie() function. To my current knowledge the GNU libc is the only library that provides this feature.

Requirements

This module uses the functions of zlib by Jean-loup Gailly and Mark Adler. You have to use a zlib version >= 1.0.9 with this module.

Installation

Zlib support in PHP is not enabled by default. You will need to configure PHP –with-zlib[=DIR]

The windows version of PHP has built in support for this extension. You do not need to load any additional extension in order to use these functions.

Note: Builtin support for zlib is available with PHP 4.3.0.

Runtime Configuration

The behaviour of these functions is affected by settings in php.ini.

The zlib extension offers the option to transparently compress your pages on-the-fly, if the requesting browser supports this. Therefore there are three options in the configuration file php.ini.

Table 1. Zlib Configuration Options

Name Default Changeable
zlib.output_compression “Off” PHP_INI_ALL
zlib.output_compression_level “-1″ PHP_INI_ALL
zlib.output_handler “” PHP_INI_ALL

For further details and definition of the PHP_INI_* constants see ini_set().Here is a short explanation of the configuration directives.

zlib.output_compression boolean/integer
Whether to transparently compress pages. If this option is set to “On” in php.ini or the Apache configuration, pages are compressed if the browser sends an “Accept-Encoding: gzip” or “deflate” header. “Content-Encoding: gzip” (respectively “deflate”) and “Vary: Accept-Encoding” headers are added to the output.

You can use ini_set() to disable this in your script if the headers aren’t already sent. If you output a “Content-Type: image/” header the compression is disabled, too (in order to circumvent a Netscape bug). You can reenable it, if you add “ini_set(’zlib.output_compression’, ‘On’)” after the header call which added the image content-type.

This option also accepts integer values instead of boolean “On”/”Off”, using this you can set the output buffer size (default is 4KB).

Note: output_handler must be empty if this is set ‘On’ ! Instead you must use zlib.output_handler.

zlib.output_compression_level integer
Compression level used for transparent output compression.

zlib.output_handler string
You cannot specify additional output handlers if zlib.output_compression is activated here. This setting does the same as output_handler but in a different order.

Resource Types

This extension has no resource types defined.

Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

FORCE_GZIP (integer)
FORCE_DEFLATE (integer)

Examples

This example opens a temporary file and writes a test string to it, then it prints out the content of this file twice.

Example 1. Small Zlib Example

<?php

$filename = tempnam ('/tmp', 'zlibtest').'.gz';
print "<html>\n<head></head>\n<body>\n<pre>\n";
$s = "Only a test, test, test, test, test, test, test, test!\n";

// open file for writing with maximum compression
$zp = gzopen($filename, "w9");

// write string to file
gzwrite($zp, $s);

// close file
gzclose($zp);

// open file for reading
$zp = gzopen($filename, "r");

// read 3 char
print gzread($zp, 3);

// output until end of the file and close it.
gzpassthru($zp);

print "\n";

// open file and print content (the 2nd time).
if (readgzfile($filename) != strlen($s)) {
echo "Error with zlib functions!";
}
unlink($filename);
print "</pre>\n</h1></body>\n</html>\n";

?>
Table of Contents
gzclose – Close an open gz-file pointer
gzcompress – Compress a string
gzdeflate – Deflate a string
gzencode – Create a gzip compressed string
gzeof – Test for end-of-file on a gz-file pointer
gzfile – Read entire gz-file into an array
gzgetc – Get character from gz-file pointer
gzgets – Get line from file pointer
gzgetss –  Get line from gz-file pointer and strip HTML tags
gzinflate – Inflate a deflated string
gzopen – Open gz-file
gzpassthru –  Output all remaining data on a gz-file pointer
gzputs – Alias for gzwrite()
gzread – Binary-safe gz-file read
gzrewind – Rewind the position of a gz-file pointer
gzseek – Seek on a gz-file pointer
gztell – Tell gz-file pointer read/write position
gzuncompress – Uncompress a deflated string
gzwrite – Binary-safe gz-file write
readgzfile – Output a gz-file

Extension Possibilities

Posted by: admin  /  Category: PHP

External Modules

External modules can be loaded at script runtime using the function dl(). This function loads a shared object from disk and makes its functionality available to the script to which it’s being bound. After the script is terminated, the external module is discarded from memory. This method has both advantages and disadvantages, as described in the following table:

Advantages Disadvantages
External modules don’t require recompiling of PHP. The shared objects need to be loaded every time a script is being executed (every hit), which is very slow.
The size of PHP remains small by “outsourcing” certain functionality. External additional files clutter up the disk.
Every script that wants to use an external module’s functionality has to specifically include a call to dl(), or the extension tag in php.ini needs to be modified (which is not always a suitable solution).

To sum up, external modules are great for third-party products, small additions to PHP that are rarely used, or just for testing purposes. To develop additional functionality quickly, external modules provide the best results. For frequent usage, larger implementations, and complex code, the disadvantages outweigh the advantages.

Third parties might consider using the extension tag in php.ini to create additional external modules to PHP. These external modules are completely detached from the main package, which is a very handy feature in commercial environments. Commercial distributors can simply ship disks or archives containing only their additional modules, without the need to create fixed and solid PHP binaries that don’t allow other modules to be bound to them.

?>