Some of Unknown and rarely used but very helpful functions of PHP
Today i have searched google and php manual to find out some of useful inbuilt functions which are not general use but having some great functionality. I found some of the function which developers rarely use but these are the very useful functions. You must spend some time to read this functions and i am sure that this functions help you while developing an application.
1. Swapping two values using list() function
$x = 1;
$y = 2;
list($x, $y) = array($y, $x);
echo $x; // Outputs – 2
echo $y; // Outputs – 1
2. Compress/Uncompress strings
You can compress long strings using gzcompress() and than make an entry in to database. This will save a space and make your database lighter at some level. You can uncompress the compressed string by using gzuncompress() function.
3. Validate real time email address
What we are validating for email address is not a perfect validation. If anyone enter aaaa@aaaaaaaa123.com than this is not a valid email address. You can validate real time email by the checkdnsrr() function. It checks the email's host address if it's a valid DNS record.
3. highlight_file() function
Output HTML string with nice colored using above function. Many servers are configured to automatically highlight files with a phps extension. To use this , you have to enable phps by adding this line to the httpd.conf:
AddType application/x-httpd-php-source .phps
4. Easy manage of IP addresses as strings.
IP address can be stored as integers using the ip2long(). If you want to convert it back to IP address from integer string than use long2ip() function.
Some of the advantages to store IP address as Integers are :
1) Less memory space used
2) Searching of IP address will be faster
3) Easy to check if IP address is inbetween IP address ranges
5. __autoload() method – PHP5
The magic method __autoload() function is a convenience that allows you to include files dynamically when instant of class is created.
This function will search file name as class name and add that file at run time. This will reduce a load time because files will be included as per needs.
6. preg_split function
This function will split string to array of strings. This can also be done using the explode function. Benifits of using preg_split function is , it will eliminate empty strings.
To know more about programming,JavaScript issues,jQuery,Expression Engine,MYSQL database,php info,php editor,programming php,Open-source,php help and php script , subscribe to our feed by entering email address below. You will get updates via email about every tutorial posted on this site . It will not take more than a sec.
Comments are closed.



I am
about 7 months ago
It was interesting to read this article and I hope to read a new article about this subject in your site in the near time.
about 7 months ago
Thanks. It was easy to understand this material. I am waiting for new information about this theme.
about 7 months ago
Really a good collection, i used all the functions other than "preg_split". I learned it now..
Thanks for the update and here is what i can share "show_source()" is one more function which works similar to highlight_file()
about 7 months ago
@ Elena ,, Thanks for commenting.. Yes i will come up with some more article about this..
about 7 months ago
@ P N V G Kishore , Thanks for sharing your knowledge with us.. Yes show_source() function is a Alias of highlight_file().
about 7 months ago
Here is a internal function/class since 5.3.0 that saved a lot of time to scan a directory recursively with multiple subfolders
http://www.php.net/manual/en/class.recursivedirectoryiterator.php