
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1060 Articles for PHP

5K+ Views
The glob function can be used to get the images from a specific folder. Below is a sample code for the same −The path to the image folder is specified and all the files that have a .png extension are extracted. They are displayed with the help of the foreach loop −$dir_name = "path/to/image/folder/"; $images = glob($dir_name."*.png"); foreach($images as $image) { echo ''; }Based on the folder that contains all images, the path of every image present inside the folder is returned.

393 Views
Use glob to find all files matching a pattern.function recursive_directory_removal($directory) { foreach(glob("{$directory}/*") as $file) { if(is_dir($file)) { recursive_directory_removal($file); } else { unlink($file); } } rmdir($directory); }On PHP version 5.3 and above, the following code can be used −$dir = ... array_walk(glob($dir . '/*'), function ($fn) { if (is_file($fn)) unlink($fn); }); unlink($dir);

4K+ Views
There is no difference between die and exit, they are the same.The PHP Manual for exit states −"This language construct is equivalent to die()."The PHP Manual for die states −"This language construct is equivalent to exit()."However, there is a small difference, i.e the amount of time it takes for the parser to return the token.

1K+ Views
The array_filter function can be used to match a partial value in an array. A callback can be provided, that helps in deciding which elements would remain in the array and which would be removed.When the callback returns false, it means the given element needs to be removed. Below is a code example demonstrating the same −$arr = array(0 => 'abc', 1 => 'def', 2 => 'ghijk', 3 => 'lmnxyz'); $results = array(); foreach ($arr as $value) { if (strpos($value, 'xyz') !== false) { $results[] = $value; } } if( empty($results) ) { echo 'No matches found.'; } else ... Read More

880 Views
SOAP and REST APIs are the widely used APIs.Consider the presence of a PHP class named manage.php that helps in managing the entries in a database.class manage { private $entryId; function __construct($entryId) { $this->entryId = $entryId; } function deleteEntry() { //delete $this->entryId from database }}On the server, this functionality can be accessed as shown below −require_once('manage.php'); $m = new manage(12); $m->deleteEntry();How can this be accessed by a different server? A third file can be created that will behave like a buffer/an interface that helps access this data. Below is a sample buffer −Let us call it ‘api/delete.php’require_once('manage.php'); if(hasPermission($_POST['api_key']) ... Read More

3K+ Views
The return value of strtolower can be passed as the third argument to str_replace (where $string is present). The str_replace function is used to replace a set of characters/character with a different set of character/string.Example Live Demo$str = 'hello have a good day everyone'; echo str_replace(' ', '-', strtolower($str));OutputThis will produce the following output −hello-have-a-good-day-everyone

288 Views
Yes, it can be done using the unlink function. It has been shown below −Another alternative that deletes the script irrespective of whether the exit function is called or not, has been shown below ^minus;class DeleteOnExit { function __destruct() { unlink(__FILE__); } } $delete_on_exit = new DeleteOnExit();

328 Views
Regular expression$directory = new RecursiveDirectoryIterator(__DIR__); $flattened = new RecursiveIteratorIterator($directory); // Make sure the path does not contain "/.Trash*" folders and ends eith a .php or .html file $files = new RegexIterator($flattened, '#^(?:[A-Z]:)?(?:/(?!\.Trash)[^/]+)+/[^/]+\.(?:php|html)$#Di'); foreach($files as $file) { echo $file . PHP_EOL; }Using filtersA base class holds the regex that needs to be used with the filter.classes which will extend this one. The RecursiveRegexIterator is extended.abstract class FilesystemRegexFilter extends RecursiveRegexIterator { protected $regex; public function __construct(RecursiveIterator $it, $regex) { $this->regex = $regex; parent::__construct($it, $regex); } }They are basic filters and work ... Read More

1K+ Views
The date function can be used to return the string formatted based on the format specified by providing the integer timestamp or the current time if no timestamp is givenThe timestamp is optional and defaults to the value of time().Example Live Demoif(date('j', $timestamp) === '1') echo "It is the first day of the month today"; if(date('D', $timestamp) === 'Mon') echo "It is Monday today";OutputThis will produce the following output −It is the first day of the month today