AmitDiwan has Published 8358 Articles

Remove duplicated elements of associative array in PHP

AmitDiwan

AmitDiwan

Updated on 09-Apr-2020 11:04:40

2K+ Views

The ‘array_map’ function sends the value of every element in the array to a user-defined function. It then returns an array with new values, because of calling the user-defined function on the array.Syntax of array_map functionarray_map ( user-defined function, array_1, array_2, array_3…)The user-defined function and the array_1 are compulsory arguments, ... Read More

Read last line from file in PHP

AmitDiwan

AmitDiwan

Updated on 09-Apr-2020 11:03:02

3K+ Views

To read last line from file in PHP, the code is as follows −$line = ''; $f = fopen('data.txt', 'r'); $cursor = -1; fseek($f, $cursor, SEEK_END); $char = fgetc($f); //Trim trailing newline characters in the file while ($char === "" || $char === "\r") {    fseek($f, $cursor--, SEEK_END);   ... Read More

Multiple index variables in PHP foreach loop

AmitDiwan

AmitDiwan

Updated on 09-Apr-2020 11:01:08

5K+ Views

The ‘foreach’ loop can be used to multiple index variables of two arrays. This has been shown below −Example Live DemoOutputThis will produce the following output −aB12 PQ34 cd90 pm49Note − If there are more than 2 arrays, nested ‘foreach’ loops can be used.Here, 2 arrays have been declared and they ... Read More

Strip punctuation with PHP

AmitDiwan

AmitDiwan

Updated on 09-Apr-2020 10:59:31

1K+ Views

The ‘preg_replace’ function can be used to match the characters in the string and remove the unnecessary characters.To keep letters and numbers −Example Live DemoOutputThis will produce the following output −Hello my name is Bobby I am 8 yearsTo keep letters only −Example Live DemoOutputThis will produce the following output −Hello my ... Read More

Detect base64 encoding in PHP?

AmitDiwan

AmitDiwan

Updated on 09-Apr-2020 10:49:18

731 Views

To detect base64 encoding in PHP, the code is as follows −Example Live Demo

How can I remove all empty values when I explode a string using PHP?

AmitDiwan

AmitDiwan

Updated on 09-Apr-2020 10:48:09

1K+ Views

The array_filter() or PREG_SPLIT_NO_EMPTY option on preg_split() can be used to remove empty values from a string when it is exploded −Example Live Demo

PHP: fopen to create folders

AmitDiwan

AmitDiwan

Updated on 09-Apr-2020 10:44:09

2K+ Views

The fopen can’t be used to create directories. This is because fopen function doesn't create or open folders, it only works with files.Before using the fopen function, one should check with is_dir first if it exists, if not create it using the mkdir function −$filename = '/path/to /file.txt'; $dirname = ... Read More

How to import csv file in PHP?

AmitDiwan

AmitDiwan

Updated on 09-Apr-2020 10:40:30

1K+ Views

The below code can be used to import CSV file in PHP −The file will display the contents of the csv file are displayed on the screen.In the above code, beginning from row 1 (since row 0 would usually contain headers/column names), the csv file is opened in read mode ... Read More

How to create a full screen search box with CSS and JavaScript?

AmitDiwan

AmitDiwan

Updated on 08-Apr-2020 11:08:47

664 Views

Following is the code to create a full screen search box with CSS and JavaScript −Example Live Demo body {    font-family: Arial; } * {    box-sizing: border-box; } .showBtn {    background: #008b0c;    border: none;    color:white;    padding: 10px 15px;    font-size: 20px; ... Read More

How to create a form with icons using CSS?

AmitDiwan

AmitDiwan

Updated on 08-Apr-2020 09:31:29

781 Views

Following is the code to create a form with icons −Example Live Demo body {    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } * {    box-sizing: border-box; } h1 {    text-align: center; } form {    max-width: 500px;    margin: auto; } .fieldContainer ... Read More

Advertisements