str_split() function used to convert a string into array.
$str = “Hello”;
$arr = str_split($str);
print_r($arr);
OUTPUT : Array ( [0] => H [1] => e [2] => l [3] => l [4] => o )
PHP is an important part of the web world, and every web developer should have the basic knowledge in PHP. Common PHP questions, which should help you become a best PHP developer.
str_split() function used to convert a string into array.
$str = “Hello”;
$arr = str_split($str);
print_r($arr);
OUTPUT : Array ( [0] => H [1] => e [2] => l [3] => l [4] => o )
array_slice() is used to extract a slice of an array. It returns the sequence of elements from the array as specified by the parameters.
$languageArray = array(“php”, “java”, “c++”, “pearl”, “python”);
$languages = array_slice($languageArray,0 ,2);
print_r($languages);
OUTPUT: Array ( [0] => php [1] => java )
1 : Instead of using SELECT * we should specify the columns name like SELECT column1,column2 which have use in our script.
2 : We should use indexing of tables for which we are writing queries.
3 : Try to use the LIMIT if we need only a specific number of rows.
We can get the browser properties in PHP by :
echo $_SERVER[‘HTTP_USER_AGENT’] . “\n\n”;
OR
$browser = get_browser(null, true);
print_r($browser);
$fileName = “file01.txt”;
//fopen() function is used to open a file in php
$file = fopen($fileName,”r”) or exit(“Unable to open the file!”) ;
While(!feof($file)) // feof()checks the end of file in php
{
echo fgets($file); // fgets() read a fileline by line in php
}
fclose($file); // fclose() used to close a file in php
We can change the time zones by using date_default_timezone_set() function
eg : date_default_timezone_set(‘America/Los_Angeles’);
We can destroy session by using session_destroy(); .
session_destroy() ;
PHP filter is used to validate the data coming from different sources like the user’s input.
It is important part of a web application to test, validate the data coming from insecure sources.
We have different functions to validate the data:
filter_var();
filter_var_array();
filter input();
filter_input_array();
email_a = ‘user@website.com’;
if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
echo “This (email_a) email address is considered valid.”;
//reported as valid
}
error_reporting(-1) will Report all PHP errors but error_reporting(0) will turn off all error reporting
For this case we can use ZipArchive class. PHP’s ZIP class provides all the functionality we need.
Please refer this link : http://www.php.net/manual/en/zip.examples.php