Improved Array-HandlingPHP

PHP  offers a plethora of new functions for accessing and manipulating arrays. These functions include, but are not limited to, array_splice(), array_push(), array_pop(), and array_diff().

Integrated Sessions  
One of the biggest problems with PHP 3 was its lack of an integrated session management system. Users either had to write their own sessions programs or rely on external session management systems, such as PHPLIB's session-handling functions. With the advent of PHP 4, the PHP Group authored a new sessions extension that allows for integrated sessions support.

Java Integration

PHP gives you the ability to integrate PHP with Java libraries and servlets. Simply create a new Java object and then you can call the Java object's methods and access its properties.

Buffering


PHP 4 offers an output-buffering subsystem that enables you access to the output of the script, manipulate it, and then do whatever you desire with the resulting data. One possible use of this feature is to create a page-caching system.

New Extensions

PHP  comes with many new extensions that weren't available with PHP 3. These extensions include, but are not limited to, the swf, curl, exif, cybercash, sockets, and ingres_ii extensions.

PEAR

PEAR stands for PHP Extension and Application Repository. The concept of PEAR is akin to that of Perl's CPAN—it is a repository of PHP classes and supporting extensions to help you program. For example, the File_Find class is distributed through PEAR. This class enables you to map and search different directory trees. More information about PEAR is available at http://pear.php.net/.


PHP's built-in substr() and substr_replace() functions, which enable you to read and write parts of the string:
<?php
$sub_str = substr ($str, $initial_pos);
$sub_str = substr ($str, $initial_pos, $str_len);

$new_str = substr_replace ($str, $replacement, $initial_pos);
$new_str = substr_replace ($str, $replacement, $initial_pos, $str_len);
?> 
 

PHP treats strings as a basic data type instead of an array of bytes. Therefore, it is possible for you to use a function such as substr() or substr_replace() to access and modify individual characters or portions of strings.

The first argument to substr() is the string on which you want to operate. The second argument to substr() specifies the beginning index of the substring you want to access. If the second argument is positive, the substring will start at that character counting from the beginning of the string. If the second argument is negative, the substring will start at that character counting from the end of the string.

Ternary Operator
 
 
the ?: conditional to test the value of the user input:
<?php

// If the user has provided a first argument to the program use
// that, otherwise STDIN (php://stdin)
$filename = isset ($argv[1]) ? $argv[1] : "php://stdin";

$fp = @fopen ($filename, 'r')
    or die ("Cannot Open $filename for reading");

while (!@feof ($fp)) {
    $line = @fgets ($fp, 1024);
    print $line;
}

@fclose ($fp);
?>

The preceding code implementing the ternary operator is the equivalent of the following:
<?php
if (isset ($argv[1])) {
    $filename = $argv[1];
} else {
    $filename = "php://stdin";
}
?>
However, PHP's ternary operator (?:) greatly reduces the time it takes for programmers to write these statements. Its syntax is as follows:
condition ? do_if_true : do_if_false;
 
The use of the ternary operator is what is known as "syntactical sugar"; that is, it is a construct that is not needed, but is a nice way of beautifying code. None the less, it can be used to replace ugly if .. else code blocks and improve the readability of your code.

The list() and array() constructs to switch the variables

 
the list() and array() constructs to switch the variables:
<?php
list ($var1, $var2) = array ($var2, $var1);
?>

In many other languages, you must use a temporary variable, like so:
<?php
$temp = $var1;
$var1 = $var2;
$var2 = $temp;
?>
However, in PHP, the list() construct does this for you. The list() construct is used to assign a list of variables

chr() and ord() or sprintf() to convert back and forth:
<?php
$letter = chr (67); // Upper case C
$ascii_code = ord ($letter); // 67

$letter = sprintf ("%c", $ascii_code); // Upper case C
?>

On the surface, converting ASCII values seems to be a pretty useless task. When I was a beginning programmer (Perl at the time), I thought that it was pointless for people even to write these functions and explanations. However, there are many cases in which you do need to convert back and forth.


To reverse all the words in a string, use a combination of the preg_split() function and the array_reverse() function:

<?php

function word_reverse ($str) {
    return implode ("", array_reverse (preg_split ("/\ s+/", $str)));
}

$str = "A rose by any other name";
$str_reversed = word_reverse ($str);
print $str_reversed;
// Outputs: name other any by rose A
?>
To reverse all the characters in a string, you can use PHP's strrev() function:
<?php

$str = "A rose by any other name";
$chars_reversed = strrev ($str);
print $chars_reversed;
// Outputs: eman rehto yna yb esor A
?> 
 
The word_reverse() function uses the array_reverse() function, which is available 
only with PHP. 



Related Posts:
  • What is an array? An array is a variablethat stores more than onepiece of related data in a single variable. Thinkof an array as a box of chocolateswith slotsinside. The box representsthe arrayitself whilethe spacescontaining chocolates rep… Read More
  • CodeIgniter config.php The  config.php filecontains a series of configuration options all of them stored in a PHP array called, appropriately enough, $config) that CodeIgniter uses to keep track of your application ’ s  information and… Read More
  • Methods and Constructors-PHP Methods are the functions defined within the class. They work within the environment of the class, including its variables. For classes, there is a special method called a constructor that's called when a new instance … Read More
  • PHP-Regular Expressions Think of regular expressions as an elaborate system of matching patterns. You first write the pattern, then use one of PHP's built-in functions to apply the pattern to a text string regular expressions are specifically f… Read More
  • Program Yahoo! with PHP 5 Take advantage of some of the latest features in PHP to quickly add Yahoo! data to PHP-powered pages. The recursively named PHP Hypertext Processor language is a popular choice for building dynamic web applications. In… Read More
  • PHP-Super global variables Global variables should be used sparingly, since it's easy to accidentally modify a variable by mistake. This kind of error can be very difficult to locate. Additionally, when we discuss functions in detail, you'll lea… Read More
  • free php script-download free php scripts | Open Source PHP - PHP Scripts gscripts.net/ A directory of free php scripts such as forums, photo galleries, CMS, and e-commerce solutions. Each script has demo so it can be tested prior to download… Read More
  • Requiring Cookies If the browser doesn’t accept cookies, a session cannot be established because the PHP directive sessions_use_only_cookies has been set to 1 and the alternative (passing the PHPSESSID in the query string of the URL) has been… Read More
  • website-secure-PHP Cryptography is the process of changing the format of data (i.e., encrypting it) so that it is more difficult to read. Some cryptography, such as PGP, available for free for public use from http://www.pgp.com,  use… Read More
  • How register the variables into a session? session_register ($session_var) function. (adsbygoogle = window.adsbygoogle || []).push({}); … Read More
  • CodeIgniter system Folder The system/ folder is where all the action happens. This folder contains all the CodeIgniter code of consequence, organized into various folders: application —  The   application foldercontains the applicat… Read More
  • Setting a session's time-PHP After a certain time period, it's reasonable to expect that a user's session should automatically log out, which is essentially an expiration period. PHP allows you to specifically set this duration. The best way to d… Read More
  • php tutorial-for beginners PHP Functions | PHP Interview Questions,PHP tutorial,seo-tips,seo tutorial,N... PHP Sessions | PHP Interview Questions,PHP tutorial,seo-tips,seo tutorial,Ne... Cookies Ver… Read More
  • Improved Array-HandlingPHP PHP  offers a plethora of new functions for accessing and manipulating arrays. These functions include, but are not limited to, array_splice(), array_push(), array_pop(), and array_diff(). Integrated Sessions&n… Read More
  • Showing the Browser and IP Address php Here is a demo page that prints out the browser string and the IP address of the HTTP request. Create a file with the following content in your web directory, name it something like demo.php, and load it in your browser. … Read More