Thursday, July 2, 2009

PHP Math Introduction

The math functions can handle values within the range of integer and float types.


Installation

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

PHP Math Constants

PHP: indicates the earliest version of PHP that supports the constant.

Constant Description PHP
M_E Returns e (approx. 2.718) 4
M_EULER Returns Euler's constant (approx. 0.577) 4
M_LNPI Returns the natural logarithm of PI (approx. 1.144) 4
M_LN2 Returns the natural logarithm of 2 (approx. 0.693) 4
M_LN10 Returns the natural logarithm of 10 (approx. 2.302) 4
M_LOG2E Returns the base-2 logarithm of E (approx. 1.442) 4
M_LOG10E Returns the base-10 logarithm of E (approx. 0.434) 4
M_PI Returns PI (approx. 3.14159) 3
M_PI_2 Returns PI/2 (approx. 1.570) 4
M_PI_4 Returns PI/4 (approx. 0.785) 4
M_1_PI Returns 1/PI (approx. 0.318) 4
M_2_PI Returns 2/PI (approx. 0.636) 4
M_SQRTPI Returns the square root of PI (approx. 1.772) 4
M_2_SQRTPI Returns 2/square root of PI (approx. 1.128) 4
M_SQRT1_2 Returns the square root of 1/2 (approx. 0.707) 4
M_SQRT2 Returns the square root of 2 (approx. 1.414) 4
M_SQRT3 Returns the square root of 3 (approx. 1.732) 4

Wednesday, July 1, 2009

PHP MySQL Introduction

The MySQL functions allows you to access MySQL database servers.
Installation
For the MySQL functions to be available, you must compile PHP with MySQL support.
For compiling, use --with-mysql=DIR (the optional DIR points to the MySQL directory).
Note: For full functionality of MySQL versions greater than 4.1., use the MySQLi extension instead. If you would like to install both the mysql extension and the mysqli extension you should use the same client library to avoid any conflicts.
Installation on Linux Systems
PHP 5+: MySQL and the MySQL library is not enabled by default. Use the --with-mysql=DIR configure option to include MySQL support and download headers and libraries from mysql.com.
Installation on Windows Systems
PHP 5+: MySQL is not enabled by default, so the php_mysql.dll must be enabled inside of php.ini. Also, PHP needs access to the MySQL client library. A file named libmysql.dll is included in the Windows PHP distribution, and in order for PHP to talk to MySQL this file needs to be available to the Windows systems PATH.
To enable any PHP extension, the PHP extension_dir setting (in the php.ini file) should be set to the directory where the PHP extensions are located. An example extension_dir value is c:\php\ext.
Note: If you get the following error when starting the web server: "Unable to load dynamic library './php_mysql.dll'", this is because php_mysql.dll or libmysql.dll cannot be found by the system.
Runtime Configuration
The behavior of the MySQL functions is affected by settings in the php.ini file.
MySQL configuration options:
Name Default Description Changeable
mysql.allow_persistent
"1"
Whether or not to allow persistent connections
PHP_INI_SYSTEM
mysql.max_persistent
"-1"
The maximum number of persistent connections per process
PHP_INI_SYSTEM
mysql.max_links
"-1"
The maximum number of connections per process (persistent connections included)
PHP_INI_SYSTEM
mysql.trace_mode
"0"
Trace mode. When set to "1", warnings and SQL-errors will be displayed. Available since PHP 4.3
PHP_INI_ALL
mysql.default_port
NULL
The default TCP port number to use
PHP_INI_ALL
mysql.default_socket
NULL
The default socket name to use. Available since PHP 4.0.1
PHP_INI_ALL
mysql.default_host
NULL
The default server host to use (doesn't apply in SQL safe mode)
PHP_INI_ALL
mysql.default_user
NULL
The default user name to use (doesn't apply in SQL safe mode)
PHP_INI_ALL
mysql.default_password
NULL
The default password to use (doesn't apply in SQL safe mode)
PHP_INI_ALL
mysql.connect_timeout
"60"
Connection timeout in seconds
PHP_INI_ALL
Resource Types
There are two resource types used in the MySQL extension. The first one is the link_identifier for a database connection, the second is a resource which holds the result of a query.
Note: Most MySQL functions accept link_identifier as the last optional parameter. If it is not provided, the last opened connection is used.
PHP MySQL Functions
PHP:
indicates the earliest version of PHP that supports the function.
Function Description PHP
mysql_affected_rows()
Returns the number of affected rows in the previous MySQL operation
3
mysql_change_user()
Deprecated. Changes the user of the current MySQL connection
3
mysql_client_encoding()
Returns the name of the character set for the current connection
4
mysql_close()
Closes a non-persistent MySQL connection
3
mysql_connect()
Opens a non-persistent MySQL connection
3
mysql_create_db()
Deprecated. Creates a new MySQL database. Use mysql_query() instead
3
mysql_data_seek()
Moves the record pointer
3
mysql_db_name()
Returns a database name from a call to mysql_list_dbs()
3
mysql_db_query()
Deprecated. Sends a MySQL query. Use mysql_select_db() and mysql_query() instead
3
mysql_drop_db()
Deprecated. Deletes a MySQL database. Use mysql_query() instead
3
mysql_errno()
Returns the error number of the last MySQL operation
3
mysql_error()
Returns the error description of the last MySQL operation
3
mysql_escape_string(
Deprecated. Escapes a string for use in a mysql_query. Use mysql_real_escape_string() instead
4
mysql_fetch_array()
Returns a row from a recordset as an associative array and/or a numeric array
3
mysql_fetch_assoc()
Returns a row from a recordset as an associative array
4
mysql_fetch_field()
Returns column info from a recordset as an object
3
mysql_fetch_lengths()
Returns the length of the contents of each field in a result row
3
mysql_fetch_object()
Returns a row from a recordset as an object
3
mysql_fetch_row()
Returns a row from a recordset as a numeric array
3
mysql_field_flags()
Returns the flags associated with a field in a recordset
3
mysql_field_len()
Returns the maximum length of a field in a recordset
3
mysql_field_name()
Returns the name of a field in a recordset
3
mysql_field_seek()
Moves the result pointer to a specified field
3
mysql_field_table()
Returns the name of the table the specified field is in
3
mysql_field_type()
Returns the type of a field in a recordset
3
mysql_free_result()
Free result memory
3
mysql_get_client_info()
Returns MySQL client info
4
mysql_get_host_info()
Returns MySQL host info
4
mysql_get_proto_info()
Returns MySQL protocol info
4
mysql_get_server_info()
Returns MySQL server info
4
mysql_info()
Returns information about the last query
4
mysql_insert_id()
Returns the AUTO_INCREMENT ID generated from the previous INSERT operation
3
mysql_list_dbs()
Lists available databases on a MySQL server
3
mysql_list_fields()
Deprecated. Lists MySQL table fields. Use mysql_query() instead
3
mysql_list_processes()
Lists MySQL processes
4
mysql_list_tables()
Deprecated. Lists tables in a MySQL database. Use mysql_query() instead
3
mysql_num_fields()
Returns the number of fields in a recordset
3
mysql_num_rows()
Returns the number of rows in a recordset
3
mysql_pconnect()
Opens a persistent MySQL connection
3
mysql_ping()
Pings a server connection or reconnects if there is no connection
4
mysql_query()
Executes a query on a MySQL database
3
mysql_real_escape_string()
Escapes a string for use in SQL statements
4
mysql_result()
Returns the value of a field in a recordset
3
mysql_select_db()
Sets the active MySQL database
3
mysql_stat()
Returns the current system status of the MySQL server
4
mysql_tablename()
Deprecated. Returns the table name of field. Use mysql_query() instead
3
mysql_thread_id()
Returns the current thread ID
4
mysql_unbuffered_query()
Executes a query on a MySQL database (without fetching / buffering the result)
4
PHP MySQL Constants
Since PHP 4.3 it has been possible to specify additional flags for the mysql_connect() and mysql_pconnect() functions:
PHP: indicates the earliest version of PHP that supports the constant.
Constant Description PHP
MYSQL_CLIENT_COMPRESS
Use compression protocol
4.3
MYSQL_CLIENT_IGNORE_SPACE
Allow space after function names
4.3
MYSQL_CLIENT_INTERACTIVE
Allow interactive timeout seconds of inactivity before closing the connection
4.3
MYSQL_CLIENT_SSL
Use SSL encryption (only available with version 4+ of the MySQL client library)
4.3
The mysql_fetch_array() function uses a constant for the different types of result arrays. The following constants are defined:
Constant Description PHP
MYSQL_ASSOC
Columns are returned into the array with the fieldname as the array index

MYSQL_BOTH
Columns are returned into the array having both a numerical index and the fieldname as the array index

MYSQL_NUM
Columns are returned into the array having a numerical index (index starts at 0)

PHP SimpleXML Introduction

The SimpleXML functions lets you convert XML to an object.
This object can be processed, like any other object, with normal property selectors and array iterators.
Some of these functions requires the newest PHP build.
Installation
The SimpleXML functions are part of the PHP core. There is no installation needed to use these functions.
PHP SimpleXML Functions
PHP: indicates the earliest version of PHP that supports the function.
Function Description PHP
construct()
Creates a new SimpleXMLElement object
5
addAttribute()
Adds an attribute to the SimpleXML element
5
addChild()
Adds a child element the SimpleXML element
5
asXML()
Gets an XML string from a SimpleXML element
5
attributes()
Gets a SimpleXML element's attributes
5
children()
Gets the children of a specified node
5
getDocNamespaces()
Gets the namespaces of an XML document
5
getName()
Gets the name of a SimpleXML element
5
getNamespaces()
Gets the namespaces from XML data
5
registerXPathNamespace()
Creates a namespace context for the next XPath query
5
simplexml_import_dom()
Gets a SimpleXMLElement object from a DOM node
5
simplexml_load_file()
Gets a SimpleXMLElement object from an XML document
5
simplexml_load_string()
Gets a SimpleXMLElement object from an XML string
5
xpath()
Runs an XPath query on XML data
5

PHP String Introduction

The string functions allow you to manipulate strings.
Installation
The string functions are part of the PHP core. There is no installation needed to use these functions.
PHP String Functions
PHP: indicates the earliest version of PHP that supports the function.
Function Description PHP
addcslashes()
Returns a string with backslashes in front of the specified characters
4
addslashes()
Returns a string with backslashes in front of predefined characters
3
bin2hex()
Converts a string of ASCII characters to hexadecimal values
3
chop()
Alias of rtrim()
3
chr()
Returns a character from a specified ASCII value
3
chunk_split()
Splits a string into a series of smaller parts
3
convert_cyr_string()
Converts a string from one Cyrillic character-set to another
3
convert_uudecode()
Decodes a uuencoded string
5
convert_uuencode()
Encodes a string using the uuencode algorithm
5
count_chars()
Returns how many times an ASCII character occurs within a string and returns the information
4
crc32()
Calculates a 32-bit CRC for a string
4
crypt()
One-way string encryption (hashing)
3
echo()
Outputs strings
3
explode()
Breaks a string into an array
3
fprintf()
Writes a formatted string to a specified output stream
5
get_html_translation_table()
Returns the translation table used by htmlspecialchars() and htmlentities()
4
hebrev()
Converts Hebrew text to visual text
3
hebrevc()
Converts Hebrew text to visual text and new lines (\n) into

3
html_entity_decode()
Converts HTML entities to characters
4
htmlentities()
Converts characters to HTML entities
3
htmlspecialchars_decode()
Converts some predefined HTML entities to characters
5
htmlspecialchars()
Converts some predefined characters to HTML entities
3
implode()
Returns a string from the elements of an array
3
join()
Alias of implode()
3
levenshtein()
Returns the Levenshtein distance between two strings
3
localeconv()
Returns locale numeric and monetary formatting information
4
ltrim()
Strips whitespace from the left side of a string
3
md5()
Calculates the MD5 hash of a string
3
md5_file()
Calculates the MD5 hash of a file
4
metaphone()
Calculates the metaphone key of a string
4
money_format()
Returns a string formatted as a currency string
4
nl_langinfo()
Returns specific local information
4
nl2br()
Inserts HTML line breaks in front of each newline in a string
3
number_format()
Formats a number with grouped thousands
3
ord()
Returns the ASCII value of the first character of a string
3
parse_str()
Parses a query string into variables
3
print()
Outputs a string
3
printf()
Outputs a formatted string
3
quoted_printable_decode()
Decodes a quoted-printable string
3
quotemeta()
Quotes meta characters
3
rtrim()
Strips whitespace from the right side of a string
3
setlocale()
Sets locale information
3
sha1()
Calculates the SHA-1 hash of a string
4
sha1_file()
Calculates the SHA-1 hash of a file
4
similar_text()
Calculates the similarity between two strings
3
soundex()
Calculates the soundex key of a string
3
sprintf()
Writes a formatted string to a variable
3
sscanf()
Parses input from a string according to a format
4
str_ireplace()
Replaces some characters in a string (case-insensitive)
5
str_pad()
Pads a string to a new length
4
str_repeat()
Repeats a string a specified number of times
4
str_replace()
Replaces some characters in a string (case-sensitive)
3
str_rot13()
Performs the ROT13 encoding on a string
4
str_shuffle()
Randomly shuffles all characters in a string
4
str_split()
Splits a string into an array
5
str_word_count()
Count the number of words in a string
4
strcasecmp()
Compares two strings (case-insensitive)
3
strchr()
Finds the first occurrence of a string inside another string (alias of strstr())
3
strcmp()
Compares two strings (case-sensitive)
3
strcoll()
Locale based string comparison
4
strcspn()
Returns the number of characters found in a string before any part of some specified characters are found
3
strip_tags()
Strips HTML and PHP tags from a string
3
stripcslashes()
Unquotes a string quoted with addcslashes()
4
stripslashes()
Unquotes a string quoted with addslashes()
3
stripos()
Returns the position of the first occurrence of a string inside another string (case-insensitive)
5
stristr()
Finds the first occurrence of a string inside another string (case-insensitive)
3
strlen()
Returns the length of a string
3
strnatcasecmp()
Compares two strings using a "natural order" algorithm (case-insensitive)
4
strnatcmp()
Compares two strings using a "natural order" algorithm (case-sensitive)
4
strncasecmp()
String comparison of the first n characters (case-insensitive)
4
strncmp()
String comparison of the first n characters (case-sensitive)
4
strpbrk()
Searches a string for any of a set of characters
5
strpos()
Returns the position of the first occurrence of a string inside another string (case-sensitive)
3
strrchr()
Finds the last occurrence of a string inside another string
3
strrev()
Reverses a string
3
strripos()
Finds the position of the last occurrence of a string inside another string (case-insensitive)
5
strrpos()
Finds the position of the last occurrence of a string inside another string (case-sensitive)
3
strspn()
Returns the number of characters found in a string that contains only characters from a specified charlist
3
strstr()
Finds the first occurrence of a string inside another string (case-sensitive)
3
strtok()
Splits a string into smaller strings
3
strtolower()
Converts a string to lowercase letters
3
strtoupper()
Converts a string to uppercase letters
3
strtr()
Translates certain characters in a string
3
substr()
Returns a part of a string
3
substr_compare()
Compares two strings from a specified start position (binary safe and optionally case-sensitive)
5
substr_count()
Counts the number of times a substring occurs in a string
4
substr_replace()
Replaces a part of a string with another string
4
trim()
Strips whitespace from both sides of a string
3
ucfirst()
Converts the first character of a string to uppercase
3
ucwords()
Converts the first character of each word in a string to uppercase
3
vfprintf()
Writes a formatted string to a specified output stream
5
vprintf()
Outputs a formatted string
4
vsprintf()
Writes a formatted string to a variable
4
wordwrap()
Wraps a string to a given number of characters
4
PHP String Constants
PHP: indicates the earliest version of PHP that supports the constant.
Constant Description PHP
CRYPT_SALT_LENGTH

Contains the length of the default encryption method for thesystem. For standard DES encryption, the length is 2

CRYPT_STD_DES

Set to 1 if the standard DES-based encryption with a 2 character salt is supported, 0 otherwise

CRYPT_EXT_DES

Set to 1 if the extended DES-based encryption with a 9 character salt is supported, 0 otherwise

CRYPT_MD5

Set to 1 if the MD5 encryption with a 12 character salt starting with $1$ is supported, 0 otherwise

CRYPT_BLOWFISH

Set to 1 if the Blowfish encryption with a 16 character salt starting with $2$ or $2a$ is supported, 0 otherwise0

HTML_SPECIALCHARS


HTML_ENTITIES


ENT_COMPAT


ENT_QUOTES


ENT_NOQUOTES


CHAR_MAX


LC_CTYPE


LC_NUMERIC


LC_TIME


LC_COLLATE


LC_MONETARY


LC_ALL


LC_MESSAGES


STR_PAD_LEFT


STR_PAD_RIGHT


STR_PAD_BOTH

PHP XML Parser Introduction

The XML functions lets you parse, but not validate, XML documents.
XML is a data format for standardized structured document exchange. More information on XML can be found in our XML Tutorial.
This extension uses the Expat XML parser.
Expat is an event-based parser, it views an XML document as a series of events. When an event occurs, it calls a specified function to handle it.
Expat is a non-validating parser, and ignores any DTDs linked to a document. However, if the document is not well formed it will end with an error message.
Because it is an event-based, non validating parser, Expat is fast and well suited for web applications.
The XML parser functions lets you create XML parsers and define handlers for XML events.
Installation
The XML functions are part of the PHP core. There is no installation needed to use these functions.
PHP XML Parser Functions
PHP: indicates the earliest version of PHP that supports the function.
Function Description PHP
utf8_decode()
Decodes an UTF-8 string to ISO-8859-1
3
utf8_encode()
Encodes an ISO-8859-1 string to UTF-8
3
xml_error_string()
Gets an error string from the XML parser
3
xml_get_current_byte_index()
Gets the current byte index from the XML parser
3
xml_get_current_column_number()
Gets the current column number from the XML parser
3
xml_get_current_line_number()
Gets the current line number from the XML parser
3
xml_get_error_code()
Gets an error code from the XML parser
3
xml_parse()
Parses an XML document
3
xml_parse_into_struct()
Parse XML data into an array
3
xml_parser_create_ns()
Create an XML parser with namespace support
4
xml_parser_create()
Create an XML parser
3
xml_parser_free()
Free an XML parser
3
xml_parser_get_option()
Get options from an XML parser
3
xml_parser_set_option()
Set options in an XML parser
3
xml_set_character_data_handler()
Set handler function for character data
3
xml_set_default_handler()
Set default handler function
3
xml_set_element_handler()
Set handler function for start and end element of elements
3
xml_set_end_namespace_decl_handler()
Set handler function for the end of namespace declarations
4
xml_set_external_entity_ref_handler()
Set handler function for external entities
3
xml_set_notation_decl_handler()
Set handler function for notation declarations
3
xml_set_object()
Use XML Parser within an object
4
xml_set_processing_instruction_handler()
Set handler function for processing instruction
3
xml_set_start_namespace_decl_handler()
Set handler function for the start of namespace declarations
4
xml_set_unparsed_entity_decl_handler()
Set handler function for unparsed entity declarations
3
PHP XML Parser Constants
Constant
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)

PHP Zip File Introduction

The Zip files functions allows you to read ZIP files.

Installation

For the Zip file functions to work on your server, these libraries must be installed:
The ZZIPlib library by Guido Draheim: Download the ZZIPlib library
The Zip PELC extension: Download the Zip PELC extension
Installation on Linux Systems


PHP 5+:
Zip functions and the Zip library is not enabled by default and must be downloaded from the links above. Use the --with-zip=DIR configure option to include Zip support.
Installation on Windows Systems
PHP 5+:
Zip functions is not enabled by default, so the php_zip.dll and the ZZIPlib library must be downloaded from the link above. php_zip.dll must be enabled inside of php.ini.
To enable any PHP extension, the PHP extension_dir setting (in the php.ini file) should be set to the directory where the PHP extensions are located. An example extension_dir value is c:\php\ext.

PHP Zip File Functions

PHP: indicates the earliest version of PHP that supports the function.

Function Description PHP
zip_close()
Closes a ZIP file
4
zip_entry_close()
Closes an entry in the ZIP file
4
zip_entry_compressedsize()
Returns the compressed size of an entry in the ZIP file
4
zip_entry_compressionmethod()
Returns the compression method of an entry in the ZIP file
4
zip_entry_filesize()
Returns the actual file size of an entry in the ZIP file
4
zip_entry_name()
Returns the name of an entry in the ZIP file
4
zip_entry_open()
Opens an entry in the ZIP file for reading
4
zip_entry_read()
Reads from an open entry in the ZIP file
4
zip_open()
Opens a ZIP file
4
zip_read()
Reads the next entry in a ZIP file
4