<?php // Example 1 $testValues = "test1 test2 test3 test4 test5"; $testArray = explode(" ", $testValues); print_r($testArray); //Array ( [0] => test1 [1] => test2 [2] => test3 [3] => test4 [4] => test5 ) // Example 2 $testValues = "test1,test2,test3,test4,test5"; $testArray = explode(",", $testValues); print_r($testArray); //Array ( [0] => test1 [1] => test2 [2] => test3 [3] => test4 [4] => test5 ) ?>
Convert array into string – PHP
<?php $testArray = array('Test1', 'Test2', 'Test3'); $testString = implode(",", $testArray); echo $testString; // Test1,Test2,Test3 ?>
Remove null values from an array – PHP
<?php $testArray = array('Test1', 'Test2', ''); print_r( array_filter($testArray)); // Array ( [0] => Test1 [1] => Test2 ) ?>
Remove duplicate entries from an array – PHP
<?php $testArray = array('Test1', 'Test2', 'Test1'); print_r( array_unique($testArray)); // Array ( [0] => Test1 [1] => Test2 ) ?>
Find out the number of elements in an array – PHP
<?php $testArray = array('Test1', 'Test2', 'Test1'); echo( count($testArray)); // 3 echo( sizeof($testArray)); // 3 ?>
Find out the length of a string – PHP
<?php echo $length = strlen("Efforts"); // 7 ?>
Find out the IP address – PHP
<?php echo $_SERVER['REMOTE_ADDR'] ?>
Find out the previous page – PHP
<?php echo $_SERVER['HTTP_REFERER'] //will return the previous page ?>
How to find out the difference between two given dates – PHP
<?php $startDate=explode("-", "02-08-2010"); $endDate=explode("-", "26-04-2007"); echo gregoriantojd($startDate[1], $startDate[0], $startDate[2]) - gregoriantojd($endDate[1], $endDate[0], $endDate[2]); //1194 ?>
How to disable error reporting in php?
<?php error_reporting(0);// Will not report any error error_reporting(-1);// Shows all errors ?>