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
Server Side Programming Articles - Page 1839 of 2650
4K+ 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
297 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();
341 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
2K+ Views
JSON structure can be created with the below code −$json = json_encode(array( "client" => array( "build" => "1.0", "name" => "xxxx", "version" => "1.0" ), "protocolVersion" => 4, "data" => array( "distributorId" => "xxxx", "distributorPin" => "xxxx", "locale" => "en-US" ) ));
265 Views
The usort function can be used to sort a multidimensional array. It sorts with the help of a user defined function.Below is a sample code demonstration −Examplefunction compare_array($var_1, $var_2) { if ($var_1["price"] == $var_2["price"]) { return 0; } return ($var_1["price"] < $var_2["price"]) ? -1 : 1; } usort($my_Array,"compare_array") $var_1 = 2 $var_2 = 0OutputThis will produce the following output −1Explanation − We have declared var_1 and var)2 with integer values. They are compared and the result is returned.
249 Views
In this tutorial, we will be discussing a program to understand map equal_range in C++ STL.This function returns a pair of iterators that bounds the range of the container in which the key equivalent to the given parameter resides.Example Live Demo#include using namespace std; int main() { //initializing container map mp; mp.insert({ 4, 30 }); mp.insert({ 1, 40 }); mp.insert({ 6, 60 }); pair it; it = mp.equal_range(1); cout
236 Views
In this tutorial, we will be discussing a program to get maximum of all subarrays of size k using set in C++ STL.For this we will be provided with a array of size N and integer K. Our task is to get the maximum element in each K elements, add them up and print it out.Example Live Demo#include using namespace std; //returning sum of maximum elements int maxOfSubarrays(int arr[], int n, int k){ set q; set::reverse_iterator it; //inserting elements for (int i = 0; i < k; i++) { q.insert(pair(arr[i], i)); } ... Read More