PHP Tutorials

81. Upload and Download files with FTP in PHP

By: David Sklar : 2008-12-01

Description: FTP stands for File Transfer Protocol and is a method of exchanging files between one computer and another. Unlike with HTTP servers, it's easy to set up an FTP server to both send and receive files.


82. Using Text-File Databases in PHP

By: David Sklar : 2008-12-01

Description: Storing your data in a text file doesn't require any additional database software to be installed, but that's pretty much its only advantage. Its main disadvantages are clumsiness and inefficiency. At the beginning of a request, you've got to lock your text file and haul out all your data from it, even if you're only using a little bit of the data. Until you unlock the file at the end of the request, all other processes have to wait around, doing nothing, which means all your users are waiting too. One of the great assets of databases is that they give you structured access to your data, so you only lock (and load into memory) the data you actually care about. The text file solution doesn't do that.


83. GDBM, NDBM, DB2, DB3, DBM, and CDB Databases in PHP

By: David Sklar : 2008-12-01

Description: PHP can support a few different kinds of DBM backends: GDBM, NDBM, DB2, DB3, DBM, and CDB. The DBA abstraction layer lets you use the same functions on any DBM backend. All these backends store key/value pairs. You can iterate through all the keys in a database, retrieve the value associated with a particular key, and find if a particular key exists. Both the keys and the values are strings.


84. Setting cookies in PHP

By: David Sklar : 2008-12-01

Description: You can pass additional arguments to setcookie() to control cookie behavior. The third argument to setcookie() is an expiration time, expressed as an epoch timestamp. For example, this cookie expires at noon GMT on December 3, 2004:


85. Find Difference between two dates in PHP

By: David Sklar : 2008-12-01

Description: Convert both dates to epoch timestamps and subtract one from the other. Use this code to separate the difference into weeks, days, hours, minutes, and seconds:


86. Reading .CSV file in PHP

By: David Sklar : 2008-12-01

Description: You have data in comma-separated values (CSV) format, for example a file exported from Excel or a database, and you want to extract the records and fields into a format you can manipulate in PHP.


87. Appending One Array to Another in PHP

By: David Sklar : 2008-12-01

Description: Merging arrays with only numerical keys causes the arrays to get renumbered, so values aren't lost. Merging arrays with string keys causes the second array to overwrite the value of any duplicated keys. Arrays with both types of keys exhibit both types of behavior.


88. Removing Duplicate Elements from an Array in PHP

By: David Sklar : 2008-12-01

Description: Once processing is completed, array_unique()is the best way to eliminate duplicates. But, if you're inside a loop, you can eliminate the duplicate entries from appearing by checking if they're already in the array.


89. Sorting an Array in PHP

By: David Sklar : 2008-12-01

Description: The sort() function doesn't preserve the key/value association between elements; instead, entries are reindexed starting at 0 and going upward. (The one exception to this rule is a one-element array; its lone element doesn't have its index reset to 0. This is fixed as of PHP 4.2.3.)


90. Encrypting and decrypting in PHP

By: David Sklar : 2008-12-01

Description: The mcrypt extension is an interface with mcrypt, a library that implements many different encryption algorithms. The data is encrypted and decrypted by mcrypt_encrypt()and mcrypt_decrypt(), respectively. They each take five arguments. The first is the algorithm to use. To find which algorithms mcrypt supports on your system, call mcrypt_list_algorithms(). The full list of mcrypt algorithms is shown in Table below. The second argument is the encryption key; the third argument is the data to encrypt or decrypt. The fourth argument is the mode for the encryption or decryption (a list of supported modes is returned by mcrypt_list_modes()). The fifth argument is an initialization vector (IV), used by some modes as part of the encryption or decryption process.