php - bzdecompress

(PHP 4 >= 4.3.3, PHP 5, PECL bz2:1.0)
bzdecompress — Decompresses bzip2 encoded data

Description

mixed bzdecompress ( string $source [, int $small] )
bzdecompress() decompresses the given string containing bzip2 encoded data.

Parameters



source
The string to decompress.
small
If TRUE, an alternative decompression algorithm will be used which uses less memory (the maximum memory requirement drops to around 2300K) but works at roughly half the speed. See the » bzip2 documentation for more information about this feature.

Return Values

The decompressed string or number of error in case of error.

Examples


Example 351. Decompressing a String

<?php

$start_str
= "This is not an honest face?";

$bzstr = bzcompress($start_str);

echo
"Compressed String: ";

echo
$bzstr;

echo
"\n<br />\n";
$str = bzdecompress($bzstr);

echo
"Decompressed String: ";

echo
$str;

echo
"\n<br />\n";

?>

php - bzcompress

(PHP 4 >= 4.3.3, PHP 5, PECL bz2:1.0)
bzcompress — Compress a string into bzip2 encoded data

Description

mixed bzcompress ( string $source [, int $blocksize [, int $workfactor]] )
bzcompress() compresses the given string and returns it as bzip2 encoded data.

Parameters



source
The string to compress.
blocksize
Specifies the blocksize used during compression and should be a number from 1 to 9 with 9 giving the best compression, but using more resources to do so. blocksize defaults to 4.
workfactor
Controls how the compression phase behaves when presented with worst case, highly repetitive, input data. The value can be between 0 and 250 with 0 being a special case and 30 being the default value. Regardless of the workfactor, the generated output is the same.

Return Values

The compressed string or number of error in case of error.

Examples

Example 350. Compressing data
 
<?php
 
$str = "sample data"; 
$bzstr = bzcompress($str, 9);
 
echo $bzstr;

?>

php - bzclose

(PHP 4 >= 4.3.3, PHP 5, PECL bz2:1.0)
bzclose — Close a bzip2 file

Description

int bzclose ( resource $bz )
Closes the given bzip2 file pointer.

Parameters



bz
The file pointer. It must be valid and must point to a file successfully opened by bzopen().

Return Values

Returns TRUE on success or FALSE on failure.

php - break

break ends execution of the current for, foreach, while, do-while or switch structure.
break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of.

<?php
$arr
= array('one', 'two', 'three', 'four', 'stop', 'five');
while (list(,
$val) = each($arr)) {
if (
$val == 'stop') {
break;
/* You could also write 'break 1;' here. */
}
echo
"$val<br />\n";
}
/* Using the optional argument. */
$i = 0;
while (++
$i) {
switch (
$i) {
case
5:
echo
"At 5<br />\n";
break
1; /* Exit only the switch. */
case 10:
echo
"At 10; quitting<br />\n";
break
2; /* Exit the switch and the while. */
default:
break;
}
}
?>

php - Booleans

This is the easiest type. A boolean expresses a truth value. It can be either TRUE or FALSE. 

Note: The boolean type was introduced in PHP 4.

Syntax

To specify a boolean literal, use either the keyword TRUE or FALSE. Both are case-insensitive.
<?php
$foo
= True; // assign the value TRUE to $foo 

?>
Usually you use some kind of operator which returns a boolean value, and then pass it on to a control structure.
<?php
// == is an operator which test
// equality and returns a boolean

if ($action == "show_version") {
  echo
"The version is 1.23";
}
// this is not necessary...

if ($show_separators == TRUE) {
  echo
"<hr>\n";
}
// ...because you can simply type 

if ($show_separators) {
  echo
"<hr>\n";
}
 

?>

Converting to boolean

To explicitly convert a value to boolean, use either the (bool) or the (boolean) cast. However, in most cases you do not need to use the cast, since a value will be automatically converted if an operator, function or control structure requires a boolean argument.
See also Type Juggling.
When converting to boolean, the following values are considered FALSE:
Every other value is considered TRUE (including any resource).
Warning -1 is considered TRUE, like any other non-zero (whether negative or positive) number!
<?php
var_dump
((bool) ""); // bool(false) 

var_dump((bool) 1); // bool(true) 
var_dump((bool) -2); // bool(true) 
var_dump((bool) "foo"); // bool(true) 
var_dump((bool) 2.3e5); // bool(true) 
var_dump((bool) array(12)); // bool(true) 
var_dump((bool) array()); // bool(false) 
var_dump((bool) "false"); // bool(true)
?>

php - Bitwise Operators

Bitwise operators allow you to turn specific bits within an integer on or off. If both the left- and right-hand parameters are strings, the bitwise operator will operate on the characters' ASCII values.

<?php

echo 12 ^ 9; // Outputs '5'
echo "12" ^ "9"; // Outputs the Backspace character (ascii 8)
// ('1' (ascii 49)) ^ ('9' (ascii 57)) = #8
echo "hallo" ^ "hello"; // Outputs the ascii values #0 #4 #0 #0 #0
// 'a' ^ 'e' = #4
 

?>
 
Table 15.3. Bitwise Operators

Example Name Result
$a & $b And Bits that are set in both $a and $b are set.
$a | $b Or Bits that are set in either $a or $b are set.
$a ^ $b Xor Bits that are set in $a or $b but not both are set.
~ $a Not Bits that are set in $a are not set, and vice versa.
$a << $b Shift left Shift the bits of $a $b steps to the left (each step means "multiply by two")
$a >> $b Shift right Shift the bits of $a $b steps to the right (each step means "divide by two")

Warning Don't right shift for more than 32 bits on 32 bits systems. Don't left shift in case it results to number longer than 32 bits.

php - bindtextdomain

(PHP 4, PHP 5)
bindtextdomain — Sets the path for a domain

Description

string bindtextdomain ( string $domain, string $directory )
The bindtextdomain() function sets the path for a domain.

Parameters



domain
The domain
directory
The directory path

Return Values

The full pathname for the domain currently being set.

Examples


Example 766. bindtextdomain() example

<?php

$domain
= 'myapp';

echo
bindtextdomain($domain, '/usr/share/myapp/locale');
?>
  The above example will output:

/usr/share/myapp/locale

php - bindec

(PHP 4, PHP 5)
bindec — Binary to decimal

Description

number bindec ( string $binary_string )
Returns the decimal equivalent of the binary number represented by the binary_string argument.
bindec() converts a binary number to an integer or, if needed for size reasons, float.

Parameters



binary_string
The binary string to convert

Return Values

The decimal value of binary_string

ChangeLog


Version Description
Since 4.1.0 The function can now convert numbers that are too large to fit into the platforms integer type, larger values are returned as float in that case.

Examples


Example 1124. bindec() example
 
<?php

echo bindec('110011') . "\n";
echo
bindec('000110011') . "\n";

echo
bindec('111');

?>

The above example will output:

51
51
7

php - bind_textdomain_codeset

(PHP 4 >= 4.2.0, PHP 5)
bind_textdomain_codeset — Specify the character encoding in which the messages from the DOMAIN message catalog will be returned

Description

string bind_textdomain_codeset ( string $domain, string $codeset )
With bind_textdomain_codeset(), you can set in which encoding will be messages from domain returned by gettext() and similar functions.

Parameters



domain
The domain
codeset
The code set

Return Values

A string on success.

php - bin2hex

(PHP 4, PHP 5)
bin2hex — Convert binary data into hexadecimal representation

Description

string bin2hex ( string $str )
Returns an ASCII string containing the hexadecimal representation of str. The conversion is done byte-wise with the high-nibble first.

Parameters



str
A character.

Return Values

Returns the hexadecimal representation of the given string.