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.

php - bcsub

Description

string bcsub ( string $left_operand, string $right_operand [, int $scale] )
Subtracts the right_operand from the left_operand.

Parameters


left_operand
The left operand, as a string.
right_operand
The right operand, as a string.
scale
This optional parameter is used to set the number of digits after the decimal place in the result. You can also set the global default scale for all functions by using bcscale().

Return Values

The result of the substraction, as a string.

Examples

Example 336. bcsub() example
<?php

$a
= '1.234';$b = '5';

echo
bcsub($a, $b); // -3 

echo bcsub($a, $b, 4); // -3.7660
?>

php - bcsqrt

Description

string bcsqrt ( string $operand [, int $scale] )
Return the square root of the operand.

Parameters


operand
The operand, as a string.
scale
This optional parameter is used to set the number of digits after the decimal place in the result. You can also set the global default scale for all functions by using bcscale().

Return Values

Returns the square root as a string, or NULL if operand is negative.

Examples

Example 335. bcsqrt() example
<?php
echo bcsqrt('2', 3); // 1.414
?>

php - bcscale

Description

bool bcscale ( int $scale )
Sets the default scale parameter for all subsequent bc math functions that do not explicitly specify a scale parameter.

Parameters


scale
The scale factor.

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 334. bcscale() example
<?php
// default scale : 3

bcscale(3);
echo
bcdiv('105', '6.55957'); // 16.007

// this is the same without bcscale()

echo bcdiv('105', '6.55957', 3); // 16.007
?>

php - bcpowmod

Description

string bcpowmod ( string $left_operand, string $right_operand, string $modulus [, int $scale] )
Use the fast-exponentiation method to raise left_operand to the power right_operand with respect to the modulus modulus.

Parameters



left_operand
The left operand, as a string.
right_operand
The right operand, as a string.
modulus
The modulus, as a string.
scale
This optional parameter is used to set the number of digits after the decimal place in the result. You can also set the global default scale for all functions by using bcscale().

Return Values

Returns the result as a string, or NULL if modulus is 0.

Notes

Note: Because this method uses the modulus operation, non-natural numbers may give unexpected results. A natural number is any positive non-zero integer.

Examples

The following two statements are functionally identical. The bcpowmod() version however, executes in less time and can accept larger parameters.
<?php
$a
= bcpowmod($x, $y, $mod);
$b = bcmod(bcpow($x, $y), $mod);
// $a and $b are equal to each other.
?>

php - bcpow

Description

string bcpow ( string $left_operand, string $right_operand [, int $scale] )
Raise left_operand to the power right_operand.

Parameters



left_operand
The left operand, as a string.
right_operand
The right operand, as a string.
scale
This optional parameter is used to set the number of digits after the decimal place in the result. You can also set the global default scale for all functions by using bcscale().

Return Values

Returns the result as a string.

Examples

Example 333. bcpow() example
<?php
echo bcpow('4.2', '3', 2); // 74.08
?>

php - bcompiler_write_header

Description

bool bcompiler_write_header ( resource $filehandle [, string $write_ver] )
Writes the header part of a bcompiler file.

Parameters


filehandle
A file handle as returned by fopen().
write_ver
Can be used to write bytecode in a previously used format, so that you can use it with older versions of bcompiler.

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 348. bcompiler_write_header() example
<?php
$fh
= fopen("/tmp/example","w");

bcompiler_write_header($fh); 
bcompiler_write_class($fh,"DB"); 
bcompiler_write_footer($fh); 
fclose($fh);
?>

php - bcompiler_write_functions_from_file

Description

bool bcompiler_write_functions_from_file ( resource $filehandle, string $fileName )
Searches for all functions declared in the given file, and writes their correspondent bytecodes to the open file handle.

Parameters



filehandle
A file handle as returned by fopen().
fileName
The file to be compiled. You must always include or require the file you intend to compile.

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 347. bcompiler_write_functions_from_file() example
<?php

require('module.php');
$fh = fopen("/tmp/example","w");

bcompiler_write_header($fh);

bcompiler_write_functions_from_file($fh,'module.php');

bcompiler_write_footer($fh);

fclose($fh);
?>

php - bcompiler_write_function

Description

bool bcompiler_write_function ( resource $filehandle, string $functionName )
Reads the bytecodes from PHP for an existing function, and writes them to the open file handle. Order is not important, (eg. if function b uses function a, and you compile it like the example below, it will work perfectly OK).

Parameters


filehandle
A file handle as returned by fopen().
functionName
The function name, as a string.

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 346. bcompiler_write_function() example
<?php
$fh
= fopen("/tmp/example","w");
bcompiler_write_header($fh);
bcompiler_write_function($fh,"my_function_a");
bcompiler_write_function($fh,"my_function_b"); 
bcompiler_write_footer($fh);
fclose($fh);
?>

php - bcompiler_write_footer

Description

bool bcompiler_write_footer ( resource $filehandle )
Writes the single character \x00 to indicate End of compiled data.

Parameters


filehandle
A file handle as returned by fopen().

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 345. bcompiler_write_footer() example
<?php
$fh
= fopen("/tmp/example","w"); 

bcompiler_write_header($fh); 
bcompiler_write_class($fh,"DB"); 
bcompiler_write_class($fh,"DB_common"); 
bcompiler_write_footer($fh); 
fclose($fh);
?>

php - bcompiler_write_file

Description

bool bcompiler_write_file ( resource $filehandle, string $filename )
This function complies specified source file into bytecodes, and writes them to the open file handle.

Parameters


filehandle
A file handle as returned by fopen().
filename
The source file path, as a string.

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 344. bcompiler_write_file() example
<?php
$fh
= fopen("example.phb", "w");

bcompiler_write_header($fh); 
bcompiler_write_file($fh, "example.php"); 
bcompiler_write_footer($fh); 
fclose($fh);
/* the following should be equivalent:
include "example.php";
and
include "example.phb";
*/
 

?>

php - bcompiler_write_exe_footer

Description

bool bcompiler_write_exe_footer ( resource $filehandle, int $startpos )
An EXE (or self executable) file consists of 3 parts:
The stub (executable code, e.g. a compiled C program) that loads PHP interpreter, bcompiler extension, stored Bytecodes and initiates a call for the specified function (e.g. main) or class method (e.g. main::main)
The Bytecodes (uncompressed only for the moment)
The bcompiler EXE footer

To obtain a suitable stub you can compile php_embed-based stub phpe.c located in the examples/embed directory on bcompiler's CVS.

Parameters


filehandle
A file handle as returned by fopen().
startpos
The file position at which the Bytecodes start, and can be obtained using ftell().

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 343. bcompiler_write_footer() example
<?php
/* creating the output file (example.exe) */ 

$fh = fopen("example.exe", "w");
/* 1) writing a stub (phpe.exe) */ 

$size = filesize("phpe.exe"); 
$fr = fopen("phpe.exe", "r"); 
fwrite($fh, fread($fr, $size), $size);$startpos = ftell($fh);
/* 2) writing bytecodes */

bcompiler_write_header($fh); 
bcompiler_write_class($fh, "myclass"); 
bcompiler_write_function($fh, "main"); 
bcompiler_write_footer($fh);
/* 3) writing EXE footer */

bcompiler_write_exe_footer($fh, $startpos);
/* closing the output file */

 fclose($fh); 
?>

php - bcompiler_write_constant

Description

bool bcompiler_write_constant ( resource $filehandle, string $constantName )
Reads the bytecodes from PHP for an existing constant, and writes them to the open file handle.

Parameters


filehandle
A file handle as returned by fopen().
constantName
The name of the defined constant, as a string.

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 342. bcompiler_write_constant() example

<?php

define
("MODULE_MAX", 30);
$fh = fopen("/tmp/example","w"); 

bcompiler_write_header($fh);  
bcompiler_write_constant($fh,"MODULE_MAX");  
bcompiler_write_footer($fh); fclose($fh);
 

?>

php - bcompiler_write_class

Description

bool bcompiler_write_class ( resource $filehandle, string $className [, string $extends] )
Reads the bytecodes from PHP for an existing class, and writes them to the open file handle.

Parameters


filehandle
A file handle as returned by fopen().
className
The class name, as a string.
extends

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 341. bcompiler_write_class() example
<?php

$fh
= fopen("/tmp/example","w");

bcompiler_write_header($fh);
bcompiler_write_class($fh,"DB");
// you must write DB_common before DB_mysql, as DB_mysql extends DB_common. 
bcompiler_write_class($fh,"DB_common");
bcompiler_write_class($fh,"DB_mysql");
bcompiler_write_footer($fh); 
fclose($fh);
 

?>

php - bcompiler_read

Description

bool bcompiler_read ( resource $filehandle )
Reads data from a open file handle and creates classes from the bytecodes.

Parameters


filehandle
A file handle as returned by fopen().

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 340. bcompiler_read() example
<?php

$fh
= fopen("/tmp/example","r");

bcompiler_read($fh);

fclose($fh);print_r(get_defined_classes());
?>

php - bcompiler_parse_class

Description

bool bcompiler_parse_class ( string $class, string $callback )
Reads the bytecodes of a class and calls back to a user function.

Parameters



class
The class name, as a string.
callback

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 339. bcompiler_parse_class() example
<?php
function readByteCodes($data) {
 
print_r($data);

}
bcompiler_parse_class("DB","readByteCodes");
?>

php - bcompiler_load_exe

Description

bool bcompiler_load_exe ( string $filename )
Reads data from a bcompiler exe file and creates classes from the bytecodes.

Parameters


filename
The exe file path, as a string.

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 337. bcompiler_load() example
<?php

bcompiler_load_exe
("/tmp/example.exe"); 


print_r(get_defined_classes());

?>

php - bcompiler_load

Description

bool bcompiler_load ( string $filename )
Reads data from a bzcompressed file and creates classes from the bytecodes.

Parameters



filename
The bzcompressed file path, as a string.

Return Values

Returns TRUE on success or FALSE on failure.

Examples


Example 338. bcompiler_load() example
 
<?php

bcompiler_load
("/tmp/example");
print_r(get_defined_classes());
?>

php - bcmul

Description

string bcmul ( string $left_operand, string $right_operand [, int $scale] )
Multiply the left_operand by the right_operand.

Parameters



left_operand
The left operand, as a string.
right_operand
The right operand, as a string.
scale
This optional parameter is used to set the number of digits after the decimal place in the result. You can also set the global default scale for all functions by using bcscale().

Return Values

Returns the result as a string.

Examples

Example 332. bcmul() example
<?php

echo bcmul('1.34747474747', '35', 3); // 47.161 
echo bcmul('2', '4'); // 8 
?>

php - bcmod

Description

string bcmod ( string $left_operand, string $modulus )
Get the modulus of the left_operand using modulus.

Parameters



left_operand
The left operand, as a string.
modulus
The modulus, as a string.

Return Values

Returns the modulus as a string, or NULL if modulus is 0.

Examples

Example 331. bcmod() example
 
<?php

echo bcmod('4', '2'); // 0 
echo bcmod('2', '4'); // 2

?>

php - BCMath Arbitrary Precision Mathematics Functions

Introduction

For arbitrary precision mathematics PHP offers the Binary Calculator which supports numbers of any size and precision, represented as strings.

Requirements

Since PHP 4.0.4, libbcmath is bundled with PHP. You don't need any external libraries for this extension.

Installation

These functions are only available if PHP was configured with --enable-bcmath. In PHP 3, these functions are only available if PHP was not configured with --disable-bcmath.
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

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

Table 22. BC math configuration options
Name Default Changeable Changelog
bcmath.scale "0" PHP_INI_ALL

For further details and definitions of the PHP_INI_* constants, see the Appendix I, php.ini directives. Here's a short explanation of the configuration directives.


bcmath.scale integer
Number of decimal digits for all bcmath functions. See also bcscale().

Resource Types

This extension has no resource types defined.

Predefined Constants

This extension has no constants defined.

php - bcdiv

Description

string bcdiv ( string $left_operand, string $right_operand [, int $scale] )
Divides the left_operand by the right_operand.

Parameters



left_operand
The left operand, as a string.
right_operand
The right operand, as a string.
scale
This optional parameter is used to set the number of digits after the decimal place in the result. You can also set the global default scale for all functions by using bcscale().

Return Values

Returns the result of the division as a string, or NULL if right_operand is 0.

Examples

Example 330. bcdiv() example
<?php
echo bcdiv('105', '6.55957', 3); // 16.007
?>

php - bccomp

Description

int bccomp ( string $left_operand, string $right_operand [, int $scale] )
Compares the left_operand to the right_operand and returns the result as an integer.

Parameters



left_operand
The left operand, as a string.
right_operand
The right operand, as a string.
scale
The optional scale parameter is used to set the number of digits after the decimal place which will be used in the comparison.

Return Values

Returns 0 if the two operands are equal, 1 if the left_operand is larger than the right_operand, -1 otherwise.

Examples

Example 329. bccomp() example
<?php
echo bccomp('1', '2') . "\n"; // -1echo bccomp('1.00001', '1', 3); // 0echo bccomp('1.00001', '1', 5); // 1
?>

php - bcadd

Description

string bcadd ( string $left_operand, string $right_operand [, int $scale] )
Sums left_operand and right_operand.

Parameters



left_operand
The left operand, as a string.
right_operand
The right operand, as a string.
scale
This optional parameter is used to set the number of digits after the decimal place in the result. You can also set the global default scale for all functions by using bcscale().

Return Values

The sum of the two operands, as a string.

Examples

Example 328. bcadd() example

<?php

$a
= '1.234';$b = '5';

echo
bcadd($a, $b); // 6echo bcadd($a, $b, 4); // 6.2340
?>

php - Basics

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.
Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
Note: For our purposes here, a letter is a-z, A-Z, and the ASCII characters from 127 through 255 (0x7f-0xff).
Tip You may also want to take a look at the Appendix T, Userland Naming Guide.
For information on variable related functions, see the Variable Functions Reference.

<?php
$var
= 'Bob';$Var = 'Joe';
echo
"$var, $Var"; // outputs "Bob, Joe"
$4site = 'not yet'; // invalid; starts with a number 

$_4site = 'not yet'; // valid; starts with an underscore
$täyte = 'mansikka'; // valid; 'ä' is (Extended) ASCII 228. 
?>
In PHP 3, variables are always assigned by value. That is to say, when you assign an expression to a variable, the entire value of the original expression is copied into the destination variable. This means, for instance, that after assigning one variable's value to another, changing one of those variables will have no effect on the other. For more information on this kind of assignment, see the chapter on Expressions.
As of PHP 4, PHP offers another way to assign values to variables: assign by reference. This means that the new variable simply references (in other words, "becomes an alias for" or "points to") the original variable. Changes to the new variable affect the original, and vice versa.
To assign by reference, simply prepend an ampersand (&) to the beginning of the variable which is being assigned (the source variable). For instance, the following code snippet outputs 'My name is Bob' twice:
<?php
$foo
= 'Bob'; // Assign the value 'Bob' to $foo

$bar = &$foo; // Reference $foo via $bar. 
$bar = "My name is $bar"; // Alter $bar...
echo $bar;
echo
$foo; // $foo is altered too.

?>
One important thing to note is that only named variables may be assigned by reference.
<?php
$foo
= 25;$bar = &$foo; // This is a valid assignment. 

$bar = &(24 * 7); // Invalid; references an unnamed expression.
function test()
{
return
25;
}
$bar = &test(); // Invalid. 

?>
It is not necessary to initialize variables in PHP however it is a very good practice. Uninitialized variables have a default value of their type - FALSE, zero, empty string or an empty array.

Example 12.1. Default values of uninitialized variables
<?php
echo ($unset_bool ? "true" : "false"); // false 
$unset_int += 25; // 0 + 25 => 25
echo $unset_string . "abc"; // "" . "abc" => "abc" 
$unset_array[3] = "def"; // array() + array(3 => "def") => array(3 => "def") 
?>

php - Basic syntax

Escaping from HTML

When PHP parses a file, it looks for opening and closing tags, which tell PHP to start and stop interpreting the code between them. Parsing in this manner allows php to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser. Most of the time you will see php embedded in HTML documents, as in this example.
<p>This is going to be ignored.</p>
<?php echo 'While this is going to be parsed.'; ?>

<p>This will also be ignored.</p>
You can also use more advanced structures:
Example 10.1. Advanced escaping
<?php
if ($expression) {?> 
<strong>This is true.</strong>
<?php } else { ?> 

<strong>This is false.</strong>
<?php }?>

This works as expected, because when PHP hits the ?> closing tags, it simply starts outputting whatever it finds (except for an immediately following newline - see instruction separation ) until it hits another opening tag. The example given here is contrived, of course, but for outputting large blocks of text, dropping out of PHP parsing mode is generally more efficient than sending all of the text through echo() or print(). There are four different pairs of opening and closing tags which can be used in php. Two of those, <?php ?> and <script language="php"> </script>, are always available. The other two are short tags and ASP style tags, and can be turned on and off from the php.ini configuration file. As such, while some people find short tags and ASP style tags convenient, they are less portable, and generally not recommended.
Note: Also note that if you are embedding PHP within XML or XHTML you will need to use the <?php ?> tags to remain compliant with standards.

Example 10.2. PHP Opening and Closing Tags
1. <?php echo 'if you want to serve XHTML or XML documents, do like this'; ?>
2. <script language="php">
echo 'some editors (like FrontPage) don\'t
like processing instructions'
;
</script>
3. <? echo 'this is the simplest, an SGML processing instruction'; ?>
<?= expression ?> This is a shortcut for "<? echo expression ?>"

4. <% echo 'You may optionally use ASP-style tags'; %>
<%= $variable; # This is a shortcut for "<% echo . . ." %>

While the tags seen in examples one and two are both always available, example one is the most commonly used, and recommended, of the two.
Short tags (example three) are only available when they are enabled via the short_open_tag php.ini configuration file directive, or if php was configured with the --enable-short-tags option.
Note: If you are using PHP 3 you may also enable short tags via the short_tags() function. This is only available in PHP 3!
ASP style tags (example four) are only available when they are enabled via the asp_tags php.ini configuration file directive.
Note: Support for ASP tags was added in 3.0.4.
Note: Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.

php - basename

Description

string basename ( string $path [, string $suffix] )
Given a string containing a path to a file, this function will return the base name of the file.

Parameters



path
A path. On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).
suffix
If the filename ends in suffix this will also be cut off.

Return Values

Returns the base name of the given path.

ChangeLog


Version Description
4.1.0 The suffix parameter was added

Examples


Example 609. basename() example
 
<?php
 
$path = "/home/httpd/html/index.php"; 
$file = basename($path); // $file is set to "index.php" 
$file = basename($path, ".php"); // $file is set to "index" 
?>