What is the use of array_slice() in PHP ?

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.

str_split()
<?php

$languageArray = array(“php”, “java”, “c++”, “pearl”, “python”);
$languages = array_slice($languageArray,0 ,2);

print_r($languages);

?>

OUTPUT: Array ( [0] => php [1] => java )

How to read the contents of a file in PHP ?

Read the contents of a file in PHP
<?php

$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

?>

What is PHP filter ?

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();

filter_var()
<?php

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
}

?>